Web Service in R8.5
John Turnbow July 12 2008 02:46:46 PM
I like the organization of all the design elements in R8.5. I like that now we have more separation for Providers and Consumers.In this example first we'll create a Provider and then create a Consumer. All of the code and explanation is below along
with a sample database for you to play with (chemicals.nsf)
As you can see in the pic above there is a clear separation of Providers and Consumers. Much nicer than in R7 or R8.0x. In
this new version all of the design elements are well categorized, easy to find and use.
First we click on "New Web Service Provider". When writing a web service with Lotusscript know that a web service exists as
a single class instance. Always remember to include "lsxsd.lss". Next we have to create our class. See the sample code below.
Dim s As NotesSession
Dim db As NotesDatabase
Dim nam As NotesName
Dim doc As NotesDocument
Dim view As NotesView
Dim dc As NotesDocumentCollection
Class ClassChemData
Public ChemicalName As String
Public Price As String
End Class
Class ClassChemicals 'include this as your port type
Sub New()
Set s = New NotesSession
Set db = s.CurrentDatabase
Set doc = db.CreateDocument 'temporary for Evaluate
End Sub
Function LookupChemical(Chem As String) As String
Set view = db.GetView("ByChemName")
Set doc = view.GetDocumentByKey(Chem,True)
If doc Is Nothing Then
LookupChemical = "Price Not Found"
Else
LookupChemical = doc.Price(0)
End If
End Function
End Class
Some relationships to know is that the PortType Class refers to the Class "ClassChemicals". Service port name for
is Domino.
Save it all and now we can look at the WSDL that Domino creates for us. A WSDL is an XML representation of the elements
and operations available in the web service. You can check this sample here.
http://www.recondite2.com/turnbow/chemicals.nsf/chemicalslist?WSDL
So, now we have our web service provider to give us some data so long as we give it the key.
So, next we create we Web Service Consumer.
We use the Provider URL to import into our new Web Consumer.
Just give the consumer a name and import the WSDL using the URL.
So, let's look at what we have. Lotus Notes does all the build for us. We'll need to use this new Web Consumer to get data from
the Provider. We'll call the LOOKUPCHEMICAL function to make a call to the web service provider.
OK, so now we have built our Provider and Consumer. Now we can start working with the Web services to pull some data. Let's build a form
to activate the consumer by giving the Consumer the chemical and credentials to do a simple lookup and value return
for us.
What we are going to do is send a Chemcial name and then return the price, very simple lookup. This is a sample only the web service
could exist anywhere.
In the button, below we'll have to set the endpoint to the Web Service URL so we know where to get our data. Next we have to do a
port.setcredentials so we can log on to the Web Service to get our data. Now that we have communicated the URL and credentials
we can can ask the provider to execute the LookupChemical function passing it the chemcial name we want our price on and return the price. That's all there is to it. - This could be the "Dblookup" web service... LOL... The sample code is below.
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim composed As String
Dim getChemical As String
Set uidoc = ws.CurrentDocument
getChemical = uidoc.FieldGetText( "Chemical" )
Dim msg As String, username As String, password As String, endpoint As String
Dim port As New ClassChemicals
endpoint = "http://www.recondite2.com/Turnbow/chemicals.nsf/chemicalsList?openwebservice"
username = "John M Turnbow"
password = "xxxxxxx"
Call port.SetEndpoint( endpoint )
Call port.SetCredentials(username, password )
Call uidoc.FieldSetText("Price", port.LookupChemical(getChemical)) 'this is where we get our Price from chemical entered.
End Sub
- Comments [1]
