March 30, 2007

A Web Service consumer

Thomas Adrian aka Notessidan has written a small web service for which he provides code to consume it. I had to try it so I did both with the suggested way in an agent using Microsoft's SOAP client and it works fine.

I also had to try using the new consumer service in Notes8. This works very good as well and this is how I did it:

  • Download the WSDL-file that describes the web service you want to call
  • Create a script library (LotusScript)
  • Press the WSDL button and import the WSDL file. When doing this on Notesidan's WSDL file my script library looks like:

    %INCLUDE "lsxsd.lss"
    Class Notessidan As PortTypeBase

    Sub NEW
    Call Service.Initialize ("UrnDefaultNamespaceNotessidanService", _
    "NotessidanService.Domino", "http://www.notessidan.se:80/A55B53/blogg.nsf/_
    notessidan?OpenWebService",
    "Notessidan")
    End Sub

    Function GETSIZE() As XSD_ANYTYPE
    Set GETSIZE = Service.Invoke("GETSIZE")
    End Function

    Function NUMBEROFDOCUMENTS() As Long
    Let NUMBEROFDOCUMENTS = Service.Invoke("NUMBEROFDOCUMENTS")
    End Function
    End Class

  • Now create an agent and use the script library. Type 'Use "scriptlib_name"' in the (Options).
  • To show for example the number of documents in a message box, use the following code in initialize:

    Sub Initialize
    Dim ns As New Notessidan
    Dim numbDoc As Long
    numbDoc = ns.NUMBEROFDOCUMENTS
    Msgbox "Number of documents: " & numbDoc
    End Sub

  • Run the agent from the Notes client or from an application in where you want to use the data.

Technorati tags:
, , , ,


12 comments:

Andrei Kouvchinnikov said...

Verkar vara ganska smidigt att anropa web service från Notes 8. Fungerar det även med complexa datatyper, som man ofta får från icke-Domino webservices? Typ en array av Telefonnummer inuti en array av Person som är inuti PersonsHolder.

Niklas Waller said...

Hej,
Jag vet faktiskt inte och har inte haft tid att kolla ännu heller. Det script library som man skapar och importerar WSDL-filen till samt agenten kan lika gärna vara skriven i Java som i Lotusscript och det kanske ger mer frihet.

Min gissning är att det går då WSDL-filen som skapas gör det enligt standarder och är inte Domino specifik vad jag vet. Om/när jag kollar det så meddelar jag.
Lämna gärna en kommentar om du eller någon annan får reda på något mer.
/ Niklas

Anonymous said...

Nick,
I am new to web services and your article helped me understand how to invoke them using Lotusscript.
Thank you very much.

Roberto

Niklas Waller said...

Roberto,
Thank's for your positive feedback. I am glad it was helpful to you!
/ Nick

Amnon said...

Nick - I run Notes 7.
when you say Press the WSDL button and import the WSDL file - I do not think I have this button on my Script Library editor, or I just cannot find it.
Any idea? -
Thanks, Amnon

Niklas Waller said...

Hi amnon,
The problem is that you run the Notes 7 client. The web service design element exists in the notes 7 client version but only to create web services for other to consume. The new web service consumer functionality comes with the notes 8 client and allows you to consume other internal or external web services.

Anonymous said...

Hi Nick,

I just wanted to say thanks! Concise and to the point your article gave me everything I needed to know to get going.

Sigi

Niklas Waller said...

Thanks Sigi, I appreciate it.
Since many people seems interested in this I am soon going to publish a new post on this blog on a web service consumer using a Java agent, where the result is parsed from an XML-structure and displayed in notes (or where you want to).

Anonymous said...

Are you still planning to post this code? I would be very interested in seeing an example of a Java web service consumer in Domino as I cannot find one anywhere...

I cannot seem to figure out how to get some classes to instantiate. I am trying to use the FedEx web services and their sample code will not work under Domino.

Niklas Waller said...

Hi,
I am now almost finished with the Java Web Service Consumer. Just need to work on some XML-parsing since the web service that Iäm using return the response in xml(?!). When this is done I will create a new post with a sample database which calls an external web service using both LotusScript and Java. Stay tuned!

Anonymous said...

Any news regarding the Java Web Consumer service? Awaiting it eagerly. :)

Jose Inacio said...

Hi! Great article!
But why am I getting an exception when I execute the agent that uses de web services consumer?
The exception is: Web Service WebServiceSoma method SOMA error org.xml.sax.SAXParseException: Espaços em branco são requeridos entre publicId e systemId.

Thank you very much!