Invoking Web services via LotusScript

If you don't want to use the IBM SOAP Connect examples, Giles Hinton provides an alternative class in LotusScript code that uses the Microsoft XMLHTTP parser to invoke and return values from a Web service.

If you don't want to use the IBM SOAP Connect examples, this class uses the Microsoft XMLHTTP parser to invoke

and return values from a Web service. This was developed for and used with C# Web services.

Here's a LotusScript example, followed by the class code. I like to keep my class in a script library. If you choose to do the same, don't forget the using statement in your agent or form. This particular example is passing a parameter to the Web service -- but you don't have to do this. If you don't want to pass parameters, just omit the ws.wsParams line.

Dim ws As New WebService("http://localhost/pathToWebService/",_
"CSharpWebService.asmx", "HelloWorld")
ws.wsParams("param1") = "testing parameters"

Title: Web Service Invoker Script Library
Version: 1.0 Alpha
Author: Giles Hinton
Last Updated: 17-Mar-2006

Public Const ERROR_CONNECTION = 20001

' Begin Class declaration

Public Class MonitorWebService
 Public wsParams List As String
 Private wsSoapFault As SOAPFault
 Private wsSession As NotesSession 
 Private wsXMLResponse As String
 Private wsSoapEnvelope As String
 Private wsURL As String
 Private wsFileName As String
 Private wsMethod As String 
 Private wsRunSuccess As Boolean
 ' Constructor
 Public Sub New(WebServiceURL As String, 
WebServiceFileName As String,_
 WebServiceMethod As String)
  Set wsSession = New NotesSession
  wsURL = WebServiceURL
  wsFileName = WebServiceFileName  
  wsMethod = WebServiceMethod
 End Sub
 Public Sub Invoke()
  Dim objHttp As Variant, objResponse As Variant
  Dim soapRequest As String
  ' Open syntax is Http Method, URL, async, username and password
  Set objHttp = CreateObject("Microsoft.XMLHTTP") "POST", wsURL & wsFileName, False
  If objHttp Is Nothing Then Error ERROR_XMLPARSER_NOT_INSTALLED, 
"XML Parser is not installed."
  objHttp.setRequestHeader "Content-Type", "text/xml"
  objHttp.setRequestHeader "SOAPAction", wsURL + wsMethod  
  soapRequest = Me.BuildSoapEnvelope()
  objHttp.setRequestHeader "Content-Length", Len(soapRequest)
  ' Soap Fault
  If Instr(1, objHttp.ResponseText, "<soap:fault>", 5) 
<> 0 Then
   Set wsSoapFault = BuildSoapFault(Strleft(Strright
(objHttp.ResponseText, "<soap:fault>", 5), "</soap:fault>", 5))
   wsRunSuccess = False
"Soap Error Encountered."
  ' Server not found
  Elseif objHttp.Status <> 200 Then 
"Could not connect to web service provider."
   wsRunSuccess = False
   Set objResponse = CreateObject("Msxml2.DOMDocument") 
   Call objResponse.loadXML(objHttp.ResponseText)
   wsXMLResponse = objResponse.xml
   wsRunSuccess = True
  End If
  Set objHttp = Nothing
  Set objResponse = Nothing
 End Sub
 Private Function BuildSoapFault
(SoapFaultXML As String) As SoapFault
  Dim faultcode As String, 
faultstring As String, faultActor As String
  faultCode = GetTagContent("faultcode", SoapFaultXML)
  faultString = GetTagContent("faultstring", SoapFaultXML)
  faultActor = GetTagContent("faultactor", SoapFaultXML)
  Set BuildSoapFault = New SoapFault
(faultActor, faultCode, faultString)
 End Function
 Private Function GetTagContent(TagName As String, 
Source As String) As String
  GetTagContent = Strleft(Strright(Source, "<" & TagName & ">", 5), 
"</" & TagName & ">", 5)
 End Function
 Private Function BuildSoapEnvelope() As String
  Dim tmpEnv As String
  tmpEnv = |<?xml version="1.0" encoding="utf-8"?>| &_
  |<soap:Envelope xmlns:xsi=
"" | &_
  |xmlns:xsd="" | &_
  |xmlns:soap="">| &_
  |<soap:Body>| &_
  |<| & wsMethod & | xmlns="| & wsURL & |">|
  ' If parameters have been specified for the web service add them now
  If Islist(wsParams) Then
   Dim paramTag As String
   Forall params In wsParams
    paramTag = Listtag(params)
    tmpEnv = tmpEnv & |<| & paramTag & |>| 
& params & |</| & paramTag & |>|
   End Forall
  End If
  tmpEnv = tmpEnv & |</| & wsMethod & |>| &_
  |</soap:Body>| &_
  BuildSoapEnvelope= tmpEnv
 End Function
 ' ********* Properties ************
 Public Property Get Successful As Boolean
  Successful = wsRunSuccess
 End Property
 Public Property Get XmlResponse As String
  XmlResponse = wsXMLResponse
 End Property
 Public Property Get ServiceURL As String
  ServiceURL = wsURL
 End Property
 Public Property Set ServiceURL As String
  wsURL = ServiceURL
 End Property
 Public Property Get ServiceFileName As String
  ServiceFileName = wsFileName
 End Property
 Public Property Set ServiceFileName As String
  wsFileName = ServiceFileName
 End Property
 Public Property Get ServiceMethodName As String
  ServiceMethodName = wsMethod
 End Property
 Public Property Set ServiceMethodName As String
  wsMethod = ServiceMethodName
 End Property
 Public Property Get ServiceSoapFaults As SoapFault
  Set ServiceSoapFaults = wsSoapFault
 End Property
End Class

Class SOAPFault
 Private fActor As String
 Private fCode As String
 Private fString As String
 Public Sub New(a As String, c As String, s As String)
  fActor = a
  fCode = c
  fString = s
 End Sub
 Public Property Get FaultActor As String
  FaultActor = fActor
 End Property
 Public Property Get FaultCode As String
  FaultCode = fCode
 End Property
 Public Property Get FaultString As String
  FaultString = fString
 End Property
End Class

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Giles Hinton. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

This was first published in May 2006

Dig deeper on LotusScript



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...