A web service consumer example

by Niklas Waller on December 16, 2008

in Lotus Notes Domino

I have just for educational purposes created a simple web service consumer with Lotus Domino Designer 8.5 Beta 2. So I thought I’d share and perhaps make someone happy.

For this example I found a web service on webservicex.net which was kind of funny. It is called BibleWebservice and let’s you get biblic information by book, chapter and verse. The address to the WSDL-file can be found here.

1. Create a web service consumer element. Name it and point to the WSDL-file either local or the url. The web service consumer gets created for you. Copy the class name that gets created, i.e. ‘BibleWebserviceSoap_n0′.

%INCLUDE “lsxsd.lss”
Const n0 = “http://www.webserviceX.NET”
Class BibleWebserviceSoap_n0 As PortTypeBase

Sub NEW
Call Service.Initialize (“HttpWwwWebserviceXNETBibleWebservice”, _
“BibleWebservice.BibleWebserviceSoap”, “http://www.webservicex.net/BibleWebservice.asmx”, _
“BibleWebserviceSoap_n0″)

End Sub

Function GetBibleWordsByChapterAndVerse(BookTitle As XSD_STRING, chapter As Long, _
Verse As Long) As XSD_STRING
Set GetBibleWordsByChapterAndVerse = Service.Invoke(“GetBibleWordsByChapterAndVerse”, BookTitle, chapter, Verse)
End Function

Function GetBibleWordsbyKeyWord(BibleWords As XSD_STRING) As XSD_STRING
Set GetBibleWordsbyKeyWord = Service.Invoke(“GetBibleWordsbyKeyWord”, BibleWords)
End Function

Function GetBookTitles() As XSD_STRING
Set GetBookTitles = Service.Invoke(“GetBookTitles”)
End Function

Function GetBibleWordsByBookTitleAndChapter(BookTitle As XSD_STRING, chapter As Long) As XSD_STRING
Set GetBibleWordsByBookTitleAndChapter = Service.Invoke(“GetBibleWordsByBookTitleAndChapter”, BookTitle, chapter)
End Function

End Class

2. Create an agent. Add “Use ‘web service consumer name’ ” in ‘Options’.
3. Set target as ‘None’ in the agent properties,
4. Add this code in the ‘initialize’ section

Dim bible As New BibleWebserviceSoap_n0
Dim bookTitles As XSD_STRING
Dim session As New NotesSession
Dim inputStream As NotesStream
Dim domParser As NotesDOMParser
Dim domDoc As NotesDOMDocumentNode
Dim domNodeList As NotesDOMNodeList
Dim domNode As NotesDOMNode

Set inputStream = session.CreateStream

Set bookTitles = bible.GetBookTitles()
Call inputStream.WriteText(bookTitles.getValueAsString())

Set domParser = session.CreateDOMParser(inputStream)
Call domParser.Process
Set domDoc = domParser.Document

Set domNodeList = domDoc.GetElementsByTagName(“BookTitle”)
Set domNode = domNodeList.GetItem(1)

‘ Now get the text in the tag and prompt it to the user (or something else)
msgbox domNode.FirstChild.NodeValue

5. Run the agent

So this agent will, when run, display the name of the first book in a message box to you which is ‘Genesis’.

Share and Enjoy:

  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • email
  • Google Buzz
  • RSS
  • Slashdot
  • Technorati
  • Add to favorites
  • DZone
  • LinkedIn
  • MySpace
  • Tumblr

Related posts:

  1. Simple parse of xml-structure in Lotus Notes
  2. Testing a Lotus Notes Web Service provider with SoapUI
  3. Working with mock objects in Salesforce web service providers
  4. Simple Ajax functionality with Ext.js and Domino
  5. Can’t provide the service under the Gmail name in Germany

{ 33 comments… read them below or add one }

Mike Bryant January 20, 2009 at 22:22

Thanks for the post. I didn’t need all the code but for the lines I did, it was very helpful!

Reply

Niklas Waller January 20, 2009 at 22:51

Thank’s for your comment Mike! Always appreciate feedback, especially good feedback

Reply

Paul Smith February 26, 2009 at 18:21

Thanks, very informative. Two other questions occurred to me:
1) any ideas where work with both versions of WSDL; ie 1.x and 2.x?
2) many web services require authentication (that is, they need to produce a certificate) from the consumer … any idea how that might work?

Paul
Huntington Beach

Reply

Niklas Waller February 27, 2009 at 16:43

Hi Paul,
Good questions.
I will have to look closer into that. Don’t know, sorry!

Reply

Peter Meuser March 2, 2009 at 14:51

One of the few consumer examples on the net – Thanks a lot Niklas.

I am still figuring out how to get back a fault message from the called web service. Any ideas?

Reply

Peter Meuser March 2, 2009 at 16:38

lsxsd.lss seems to be the only documentation about the ws implementation

[...]
Dim fault As WS_Fault
Set fault=service.getLastFault()
FaultCode$=fault.GetFaultCode()
FaultString$=fault.GetFaultString()
[...]

Reply

Niklas Waller March 2, 2009 at 17:19

Peter,
Glad you find it useful!
I have not tried this out either. I took a quick look at lsxsd.lss as you suggested and the class ‘WS_FAULT’. I will try this later on and add it to the code if it works.

Thanks!

Reply

Nitin June 1, 2009 at 07:54

Hi All,

In my new project I have to consume a SharePoint WebService in Domino agent, Where I have to CheckOut/ChckIn the SharePoint document.
I have written the code below to do so….
Dim client
Dim wsDetails As String
‘Dim theInstantV As Variant
‘theInstantV = Now

Dim test As New soapclient(“”)

‘Assigned a SharePoint WebService URL
Const sWSDL = “http://gb0000nw4582:8015/_vti_bin/lists.asmx?WSDL
‘Created a SOAP object to provide the webservice
Set Client = CreateObject(“MSSOAP.SoapClient”)
‘Initialise and call the webservice soap object
Call Client.mssoapinit(sWSDL)
‘CheckInFile function in sharepoint needs three parameter (PageURL, Comment, CheckInType)
‘Called the CheckInFile function available in SharePoint lists.asmx webservice
wsDetails = Client.CheckInFile(“http://gb0000nw4582:8015/sites/rad/Shared Documents/icon-info.jpg”, “Nitin to CheckIn”, “1″)
Msgbox wsDetails
The above code works fine when I run the agent manually, like right click on agent and say “RUN” but when I run this agent from Webbased notes form its giving an error as “Cannot create automation object”.
This error is coming on this line “Set Client = CreateObject(“MSSOAP.SoapClient”)”.

I read on internet I found that the SOAPClient needs to be installed on domino server but my client are not allowing me to install.
Is there any other option to consume the sharepoint webservice in domino?
Yours help/guidance/views are very much appericiated.

Reply

Niklas Waller June 1, 2009 at 21:50

Hi Nitin,
I took a quick look on the Internet to see if I could find anything for you. Unfortunately I have no experience myself on Sharepoint.
I found no solutions, only two ideas that might help you or not.

1. http://tinyurl.com/kj9o6u
2. http://tinyurl.com/m7kr5r

Have you tried creating a web service consumer like the one I have demonstrated in this blogpost? The problem for you obviously is the creation of the Soap client object. If you use Domino’s own SOAP client it might work? (which is what is done in this example).

Hope it works for you!

// Niklas

Reply

Nitin June 2, 2009 at 09:18

Hi Niklas,
Thanks for reply.
I follow the process given in website below, this is an IBM website and they are saying about copying some soap files into our domino folders….plz have a look into it.
http://www.ibm.com/developerworks/webservices/library/ws-soapcon/

I have written this code in my lotus agent and this use to call on WebQuerySave agent,
In Options,
Option Public
%INCLUDE “SoapConnect”

In Initialize,

‘Assigned a SharePoint WebService URL
Const sWSDL = “http://gb0000nw4582:8015/_vti_bin/lists.asmx?WSDL

Dim objBookingService

Set objBookingService = CreateObject(“MSOSOAP.SoapClient30″)
‘Set Headers
objBookingService.ClientProperty(“ServerHTTPRequest”) = True

‘Load the WSDL locally, as the WSDL on the server needs a user name and password.
objBookingService.mssoapinit(sWSDL)

Now I am getting different error, the error is,
“WSDLReader: WSDLReader:XML Parser failed at linenumber 0, lineposition 0, reason is: System error: -2147012889. HRESULT=0×1: Incorrect function. – WSDLReader:Loading of the WSDL file failed HRESULT=0×80070057: The parameter is incorrect. – Client:One of the parameters supplied is invalid. HRESULT=0×80070057: The parameter is incorrect.”

on line this,
objBookingService.mssoapinit(sWSDL)

I browsed thorough lots of sites but didn’t get proper answer, could you please check at your end.

Thanks,
Nitin.

Reply

Niklas Waller June 6, 2009 at 20:51

Nitin,
First I have a question before we start to analyze too deep. Which version of the Domino designer client do you have and which version is the Domino server on which the consumer is located?

Reply

Niklas Waller November 1, 2009 at 12:48

Hi Ferhat,

The code in the web service consumer and the agent doesn’t match. The web service consumer refers to some temp webservice and not webserviceX.net. Then class name is ‘TempConvertSoap_n0′ and the methods are some converting temperature methods.

In the agent however you are trying to create an instance of ‘BibleWebserviceSoap_n1′ to variable ‘bible’. But first of all that class isn’t defined anywhere from what I can see and hence the methods are not defined.

Maybe you attached the wrong web service consumer class?

// Niklas

Reply

Ferhat October 30, 2009 at 08:25

I tried this example but there is a problem.

Client : Lotus Notes 8.5.1 – Server : Domino 8.5

I tried your example.

WebService Consumer :
%INCLUDE “lsxsd.lss”
Const n0 = “http://tempuri.org/
Class TempConvertSoap_n0 As PortTypeBase

Sub NEW
Call Service.Initialize (“HttpTempuriOrgTempConvert”, _
“TempConvert.TempConvertSoap”, “http://www.w3schools.com/webservices/tempconvert.asmx“, _
“TempConvertSoap_n0″)

End Sub

Function FahrenheitToCelsius(Fahrenheit As XSD_STRING) As XSD_STRING
Set FahrenheitToCelsius = Service.Invoke(“FahrenheitToCelsius”, Fahrenheit)
End Function

Function CelsiusToFahrenheit(Celsius As XSD_STRING) As XSD_STRING
Set CelsiusToFahrenheit = Service.Invoke(“CelsiusToFahrenheit”, Celsius)
End Function

End Class

Agent :
%REM
Agent getBible
Created Oct 29, 2009 by Ferhat BULUT/BESTCODER
Description: Comments for Agent
%END REM
Option Public
Option Declare

Use “BibleWebservice”
Sub Initialize()

On Error GoTo ErrorHandler

Dim bible As New BibleWebserviceSoap_n1
Dim bookTitles As XSD_STRING
Dim session As New NotesSession
Dim inputStream As NotesStream
Dim domParser As NotesDOMParser
Dim domDoc As NotesDOMDocumentNode
Dim domNodeList As NotesDOMNodeList
Dim domNode As NotesDOMNode

Set inputStream = session.CreateStream

Set bookTitles = bible.GetBookTitles()
Call inputStream.WriteText(bookTitles.getValueAsString())

Set domParser = session.CreateDOMParser(inputStream)
Call domParser.Process
Set domDoc = domParser.Document

Set domNodeList = domDoc.GetElementsByTagName(“BookTitle”)
Set domNode = domNodeList.GetItem(1)

‘ Now get the text in the tag and prompt it to the user (or something else)
MsgBox domNode.FirstChild.NodeValue

Exit Sub

ErrorHandler:

MessageBox “Form : XXXX – Sub : XXXX” + Chr ( 13 ) + _
“Error No : ” + Str ( Err ) + Chr ( 13 ) + _
“Description : ” + Error$ + Chr ( 13 ) + _
“Error Line Number : ” + CStr ( Erl )

End Sub

I got an error when i want to run this agent.

Error Code : 4746
Description : Web Service BibleWebserviceSoap_n1 method GetBookTitles error Web service BibleWebserviceSoap_n1 does not have specified service method GetBookTitles

I think, lotus doesn’t get GetBookTitles function at BibleWebserviceSoap_n1 webservice. I don’t understand why ?

In the server configuration :
Internet Protocols -> Domino Web Engine -> Session authentication: Disabled

Internet Protocols -> Domino Web Engine -> Run web agents and web services concurrently? : Enabled

Internet Protocols -> Domino Web Engine -> Domino XML Services : Enabled

Any idea about this problem ?

Regards
Ferhat

Reply

huskymom August 4, 2011 at 18:49

anything more on why the 4746 error on method Get Book Titles; trying the Bible Webservice Sample in Notes 8.5.2. Could it be that the site is no longer available, or should there be some sort of an input to pass on the method call?

Reply

Oes Tsetnoc October 30, 2009 at 09:28

nice article , i will try to my website servise customer

Reply

Software companies UK December 3, 2009 at 13:06

Cool,

Great example,

Thanks for writing about it

Reply

Bill Hanson December 16, 2009 at 19:08

Hi Niklas,

Thanks for writing this article.

My current challenge is to integrate some Domino apps with our Salesforce.com instance. Have you had any success creating a consumer in Notes for the enterprise wsdl. Our enterprise WSDL imports without errors, but then there are duplicate classes (Manticore_Marketing_Activity_History_n2) and the ‘EmailServicesAddress_n2′ class is defined with a member named ‘Function’, which is a reserved word. Once I straightened those out manually(merged the manticore classes and renamed the ‘Function’ member), the script still would not save. The error message when saving was “The requested operation failed”. I wonder if this is a problem with our instance or the enterprise wsdl in general.

What has been your experience (I noticed that you wrote a SFDC article, so I assumed you’ve already tried this)?

Reply

Niklas Waller December 16, 2009 at 19:42

Hi Bill,
Glad you appreciate it!

I have not that much experience in Salesforce yet så unfortunately I don’t know the answer to your question. However this has been in my todo list for a while now, so I will check this up and get back with my results.

Thanks for stopping by!

// Niklas

Reply

Niklas Waller December 23, 2009 at 07:47

Bill,
I have tested this now and I have similar problems.
I have no issues with the Manticore class but I have the same problem with the function in the EmailServicesAddress_n2 class.

When trying to get around this I also get ‘The requested operation failed’ when saving. Seems to be a general problem thus…

Reply

Bill Hanson January 4, 2010 at 18:36

Thanks for checking. I still don’t have a working solution for this. I’m currently using COM for my Domino to SFDC integration, but I would love to ditch the COM.

Recently, I tried using the partner.wsdl. It imports and saves properly, but now I am having problems setting the session ID in the soap object’s session header. Do you know how this can be done? Is there a reference for the NotesWebServiceEngine class available somewhere? I’m hoping to find a ‘setHeaderValue’ method or maybe a way to set the header values via Invoke.

Reply

Damien Marshall January 11, 2010 at 04:06

Bill & Niklas,

I really appreciate reading your experiences here…
I am currently involved in migrating a Lotus Notes application to Salesforce.

I have been using Lotus Notes for years, but have never implemented any (complicated) “Domino” – so I don’t know much about web services.

Do either of you know if it is possible to get Lotus Notes to connect to Salesforce and upsert data to Salesforce ??
My current plan is to invesigate using Web Services to do this – but if you can tell me it is not possible then that would save me some time – I am very surprised there isn’t much documented on how to do this – which makes me think it can’t be done…

Thanks in advance…

Reply

Niklas Waller January 11, 2010 at 08:40

Hi Damien,
I might be able to help you here.

I have been responsible for a migration project where data from a Lotus Domino application involving several Notes databases were migrated to Salesforce. Salesforce themselves were also involved in the project although not in the actual migration. The recommendation from there side was to use the Data Loader (http://wiki.developerforce.com/index.php/Apex_Data_Loader) which is a tool that can be used to extract or insert/upsert or delete data in Salesforce. You can download the tool for free (Setup -> Data Management -> Data Loader).

So this is way to go to upsert or insert data (migrate) and the idea very briefly (for a Sales application) is to start upserting data from the top to bottom. What that means is that first you need the top owners (User object), then Accounts, then the children to Accounts etc. Since each object need a reference to their parent if they have one this is the way to go.

Web services can then be used to integrate with other systems. Data Loader is also using web services but that is nothing we have to bother with really.

There are also several connectors but they are used for other purposes. One is for synchronizing email and calendar between Salesforce and Lotus Notes for example and another one is used for integrating Salesforce with Excel (http://sforce.sourceforge.net/excel/index.htm).

Hope that helps! If you need to I can probably assist with other migration tips since I have already been going through this journey once.

Reply

Damien Marshall January 12, 2010 at 01:24

Niklas,

Thanks for that information.

We are already using CSV extracts from Notes to get the data into Salesforce using the DataLoader – for most of the ‘migrated’ data (Accounts, Contacts etc) this is great for a one off data transfer, but we also need to regularly synch users of SF with a HR database (in Notes).

At this stage we may be using a scheduled Data Loader batch job to process the CSV – but I was hoping to build something a bit more robust via Domino web service.

I will have a look at the Excel connector to see if I can learn how to get Domino to login to Salesforce and see where that takes me…

I am surprised not many people are integrating these two platforms – the only ‘integration’ seems to be from an email & calendar point of view – not generic Lotus Notes database to SF tables…

Thanks again…

Reply

Niklas Waller January 12, 2010 at 07:50

Damien,
Ok, I see.
We are using web services as well for several external systems that we need to integrate Salesforce with.

For two of the systems we call the Salesforce web services directly from Domino and one of them has Domino Web services implemented too. For most of the other external systems we have a middle layer which deals with all of the integration since not all systems are modern enough to communicate via web services. Anyway, this is working very well and the middle layer are using Web Methods.

My experience from this is also that there are not too many use cases with system integration between Salesforce and Domino.

Reply

Nicolas Reghem January 14, 2010 at 16:30

Hello,
I just tried this example and I got an error: 403 Forbidden. I don’t understand why.
I tried to create a very basic WS in another database and call it, but I got exactly the same error message.

I can’t find any help on this… do you have an idea ?

Thanks a lot
Nicolas

Reply

Nicolas Reghem January 14, 2010 at 17:14

Additional information:
I use a client version 8.0.2.
I tried another test… instead of executing the agent on my local computer, I ran it on the server (by using another agent and the method “runonserver”). And it works with my own web service… so I assume the problem comes from the Notes client… any preferences is wrong or something else ?
This test still doesn’t work with your example, but the error message is not the same: error: Web Service BibleWebserviceSoap_n0 method GetBookTitles error Error connecting to ‘www.webservicex.net’ on port ’80′, The remote server is not a known TCP/IP host.

Whereas the website is available…

Thanks in advance for your help

Reply

Michael March 1, 2011 at 21:35

Here is the answer for including authentication credentials.
http://blog.chrisfogarty.com/2009/09/web-service-consumer-with-credentials.html

Reply

Chris M. May 6, 2011 at 04:38

Did you ever get the fault trapping working? I am calling a simple function for a consumed sharepoint web service. A get a fault but only a basic notes dialog box showing this with no additional information. I would love to trap the error and find out what is really going on. I am accessing the getlistitems function to return a list and use it on a lotus notes form. Thanks. Great example.

Reply

Niklas Waller May 6, 2011 at 07:14

Hi Chris,
No, I’m sorry to say I never took the time to look further into this. And now attention is needed elsewhere. I would be glad if you posted here if/when you find a solution.

Thanks for stopping by!

Reply

Dennis February 3, 2012 at 21:59

Hi Niklas! Thank you for the example. I seem to be having difficulting creating a domDoc with the data. As I run the script through the debugger, I can see the data in the XSD String, however, when I parse it the domDoc does not contain the data. I realize that you’r probably quite busy, but hope that perhaps the answer is simple.
Thank you!
Dennis

Reply

Niklas Waller February 4, 2012 at 09:25

Hi Dennis,
Unfortunately I don’t work much with Notes & Domino these days. In fact, I don’t even have a test environment right now, so unfortunately I can’t help debugging and only guess. Perhaps someone else can help?

This was created with a beta version of Designer 8.5 in 2008 so perhaps a change is required.

Good Luck!

Reply

Dennis February 4, 2012 at 13:54

Hi Niklas!
Thank you for your reply. I’m sorry to hear you’ve moved away from Notes and Domino, but I understand.

Thanks you again and Best Wishes!
Dennis

Reply

Diane February 9, 2012 at 09:02

Hello,

Lotus Notes :
Please help what does “Operation Failed” causes. I am having a problem with that I think it is because of email sending but I am not sure. Please help!

Reply

Leave a Comment

Previous post:

Next post: