Consuming Web Services

Hello,I’d like to know if there is any good documentation or tutorials regarding consuming web services with Notes 8.

If I want to consume a Webservice in any of my Notes Clients - what infrastructure do I need? Do I need a Websphere server or anything?

Subject: My first steps…

I just spent some time figuring some basic things out, and I found VERY little information of any use anywhere on the Web or in the help files. Either this is too easy to be worth spending time documenting, or consuming Web Services from Domino just hasn’t taken off yet…

Anyway, for what it’s worth, here’s what I’ve found so far:

To get started with a basic example you need a basic Web Service, for instance this:

*** Start of WS Code ***

Class OneSet

’ A class defined just to contain two values

Public ValueA As String

Public ValueB As String

End Class

Class NotesOperations

’ The class providing services to the world

Private ns As NotesSession

Private db As NotesDatabase

Public Sub New ()

’ I just put this here because I’ll do something useful with it some day

  Set ns = New NotesSession

  Set db = ns.CurrentDatabase

End Sub

Public Function getValue As String

’ A function returning a string

  getValue = "Hello World"

End Function

Public Function getValues As OneSet

’ A function returning a set of two strings

’ This demonstrates what happens if a service

’ returns a “non-standard” type response

  Set getValues = New OneSet		

  getValues.ValueA = "Hello"

  getValues.ValueB ="World"

End Function

End Class

*** End of WS Code ***

Now, set the PortType Class and Port type name for the Web Service to “NotesOperations”. The Soap Message Format should be “Doc/Litoral” and the Programming Model “RPC”.

To consume this service from Domino 8, you do the following:

  1. Get the WSDL for the service to be consumed. The service above can be found at http://yourserver/yourpath/yourdb.nsf/yourWebServiceName?WSDL

Open the URL in a browser and save the XML file you get.

  1. Create a LotusScript Script Library and name it whatever you like, e.g. “WSLibrary”.

  2. In Designer 8 there’s a button at the bottom of your script library window with “WSDL…” on it. Push the button and choose “Import WSDL”.

  3. Choose the XML file from Step 1, and Domino will create some code that you don’t have to touch:

*** Beginning of automatically created code ***

%INCLUDE “lsxsd.lss”

Class ONESET As XSD_ANYTYPE

Public VALUEA As String

Public VALUEB As String

Sub NEW

End Sub

End Class

Class NotesOperations As PortTypeBase

Sub NEW

  Call Service.Initialize ("UrnDefaultNamespaceNotesOperationsService", _

     "NotesOperationsService.Domino", "http://yourserver/yourpath/yourdb.nsf/yourWebServiceName?OpenWebService", _

     "NotesOperations")

End Sub

Function GETVALUE() As String

  Let GETVALUE = Service.Invoke("GETVALUE")

End Function

Function GETVALUES() As ONESET

  Set GETVALUES = Service.Invoke("GETVALUES")

End Function

End Class

*** End of automatically created code ***

(I really wish the automatic UPPERCASING wouldn’t happen, but it does.)

As you can see, the skeleton of the original Web Service is recognizable. The function GetValue has kept its type, string, while the two-value class OneSet has now been given the generic type “XSD_AnyType”. This is important to notice!

This script library can now be used to call the Web Service from an agent.

Here’s an example agent in its simplest form:

*** Beginning of agent code ***

Option Public

Option Declare

’ Linking in the script library you just created:

Use “WSLibrary”

Sub Initialize

’ Connecting the library function that

’ in turn will call the actual Web Service

’ Note that you need to use the PortTypeBase

’ from the library to map to the service

’ object in your code

Dim MyWebService As New NotesOperations

Dim result As String

Dim results As Variant

’ First we call the Web Service that just

’ returns a string and prints it

result = MyWebService.GetValue

Print result

’ Then we call the Web Service that

’ returns two values and prints it

’ The results object is a variant, and

’ with the XSD_AnyType “type”, you don’t

’ use results(0)… results(n) to get your

’ values, but results(ParameterName) instead

Set results = MyWebService.GetValues

Print results.ValueA

Print results.ValueB

End Sub

*** End of agent code ***

That should get you started, but I really hope IBM/someone will put up a few useful examples of actual Web Service consumption, preferably against real life Web services with both simple and complex responses!

Bjørn

http://bjornfree.com/

Subject: Thanks a lot it really worked at my end…

Hi Bjoern,

Thanks for uploading this helpful sample to understand the behaviour of webservices in domino.

It has really solved my last couple of month of tech. mystery. May be it was simple to use web service but to have it worked properly is great achievement for me…

Thanks much again . and God bless you mate…

Keep up your exploration of new enhancement of R8…

Subject: GETVALUE error (404) Not Found

I followed the above instructions (with the exception of ND8-I put my code in the Web Service Providers and Web Service Consumer sections). My wsdl file and Library code were created automatically with no problems.

Upon executing my agent, I am getting the following error:

GETVALUE error (404) Not Found

Th error is occuring in the WSLibrary - getValue() function:

Let GETVALUE = Service.Invoke(“GETVALUE”)

I tried varrying case combinations, but no success.

Any ideas as to why I am getting this error?

Subject: Thanks

Thanks a lot, that was really helpful!

Subject: TLCC has a course on XML and web services for Domino

It covers both LS and Java and web services for both the server and client.TLCC Course Details - Using XML and Web Services in Domino 8

Howard

Subject: Notes 8?

With Notes8 you can both consume and provide webservices. They can even be written in LS, and a consumer can be triggered by the client, just as easy as clicking a button.

Rune

Subject: Yes, Notes 8

Thank you for the reply!Is there any good tutorial regarding the consumption of web services?

Also is it sufficient to write a script library and import a WSDL file (from an external, not related to Notes/domino service) and then writing an agent and using it in an application where I use the data that I am getting from a Webservice or do I need a special infrastructure like a Websphere server to have something like wrapper services that call other external web services?

Subject: fairly easy

For the most part it is fairly easy to create a webservice consumer.

  1. Create a script library. Click WSDL->Import WSDL. Select your WSDL file from your Web Service of choice.

The code is automatically created.

  1. There will be a file called

    …Service.java

This file contains comments on how to talk to the Web Service.

For lotusscript it is pretty much the same deal, just make sure the URL is correct when importing (you will see in the script library).

  1. Create your agent, create your Webservice object and call the method on the object.

Need to point to corrrect Web Service!

Contained in …ServiceLocator.java

private final java.lang.String Domino_address = “http://…”