Web Service is very useful method for the interaction with other machines over network.To leverage web services in Domino, a New feature called Web Service is added in R7 onwards. From R8 onwards this feature is further divided into two sections "Web Service Providers" and "Web Service Consumers". With both the options, you can create web service which can be read by other platform and vice versa. Domino can consume web services written on other platform.
In this post , I will create a web service using Domino 8.5 and will read that web service in my Eclipse application. Let's begin with the example.
I've a Lotus Notes application which keeps airlines travel availability configurations. Let's say my form name is "CheckMyTravelDate" with five fields; Departure date,Return date,From country,To country and availability status.Here is my form ,
Next, Create a view which will be used for look-up in our web service code.It will have two columns; First column is with key "Start Date-End Date-From-To" and second column is "Availability Status". We need to make first column categorized. Shown below,
Let's begin with Web Service.
Since we're going to provide Web Service, so click "New web service provider" button under "Web Service providers" section.
You will have two options to write web service ; Lotus Script and Java. Choose "Lotus Script" (default). Paste following code in your web service ,
Function getTravelStatusString(StartDate As String, EndDate As String, Departure As String, Returns As String) As String
Dim s As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim key As String
Dim sd As New NotesDateTime(StartDate)
Dim ed As New NotesDateTime(EndDate)
Set db = s.CurrentDatabase
If Not(db.IsOpen) Then
getTravelStatusString = "Cannot open travel configuration database "
Set view = db.GetView("CheckMyTravelDate")
If view Is Nothing Then
getTravelStatusString = "Cannot open travel configuration view "
key = Cstr(sd.DateOnly)+"-"+Cstr(ed.DateOnly)+"-"+Departure+"-"+Returns
Set doc = view.getDocumentByKey(key)
If doc Is Nothing Then
getTravelStatusString = "Sorry, Booking is not available with specified details"
What my code does :
It's pretty simple program implemented using class called getTravelStatus which has one function called getTravelStatusString.This function takes four arguments;Travel start date,end date,departure country and return country. It builds the key , pass to the view,get the availability status and returns to the calling function.
Now when we try to save web service, we will get following warning
Warning says, your class name should match with PortTypeClass.Open web service property window and paste your class name in PortTypeClass section.
Go to third tab of web service property window and select Programming model as RPC and SOAP message format as RPC/encoded.At the end specify other details like Port type name , service element name and Service port name which are optional parameters.Save your changes.
Now you've to run your web service on browser using ?WSDL ( http://server/database/getTravelStatus?WSDL ) command to verify everything is fine.If everything is fine, you get screen like,
You've successfully created web service, now time to test.
There are various method to test web service . I'm going to use Eclipse and the Web Tools Platform (WTP). To do so , first install Eclipse and then configure WTP in your machine.
Once installed and WTP configured is done, Open Eclipse and go to Run->Launch the Web service explorer. Click on "WSDL" page icon on top right top open WSDL window.
(or follow the same step mentioned here)
Click on "WSDL main" at left panel and provide your web service path at right panel and click on "Go".
You can check the status at lower panel whether your web service is successfully opened or not.Click on your web service name under "Operations" section.You can find the form to enter , Travel start date, end date,to country and from country . Enter data and click "Go",
So these were the basic steps to implement and test web services in Lotus Notes.
Write me for any suggestions/comments.