I got asked recently by a customer how they could have a SharePoint site talk to a Domino web server to obtain information from it. Obviously there are lots of options, but the one I ended up suggesting was Web Services.
Before making the suggestion I wanted to be extra sure it was a) possible and b) as easy as I thought it would be. To do this I created a very simple test. Here's how.
Step 1: Create a Web Service in Domino
The first thing I did was create a database called WebServces.nsf and open it in Designer. Then I created a Web Service Provider, called SimpleService, like so:
I chose to make it Java-based, but it could equally be LotusScript for the simple case I'm about to cover.
Next I renamed the Untitled.java file in the Web Service to SimpleService.java and then specified this class as the "port type" for the Service, as below:
Then, I opened the SimpleService.java file and added a simple method called getServerName() which does nothing other than return the name of the Domino server the Web Service is running on.
And that's it for Domino side of things! Nice and simple.
Step 2: Connect To Domino From ASP.NET
As I didn't have a SharePoint setup to hand I used a new ASP.NET MVC website to test it from the C# side of things.
After launching Visual Web Developer (free download) I created a new Project called "DominoFromMVC", and chose "MVC 3 Web Application", as below:
On the next screen of the dialog above I chose "Internet Application" so that it would create a basic site for me to work with.
Now, in the Solution Explorer pane I right-clicked the "Service References" section and chose "Add Service Reference..." option, as below:
At this point you need to make sure that the Domino Web Service is accessible by an Anonymous user (it took me a while to work this one out - doh)!
In the dialog that appears we need to tell it where the Domino Web Service is by specifying its URL, like so:
Notice that I called it "SimpleDominoService", which we'll see referenced again below (although it's called "DominoWebService" in some screenshots as it took two attempts to get them right!).
At this point Visual Studio interrogates the WSDL for the Web Service and creates the corresponding classes in C# so we can use then in our code.
To use the Domino Web Service in C# the first thing I did was open up the HomeController.cs file ("controllers" are the C in MVC), as below, and then added the lines highlighted in yellow:
The first line I added tells the code we're going to use new service. The other two lines and to use the service and are simply:
SimpleServiceClient dominoServiceClient = new SimpleServiceClient();
ViewBag.DominoServerName = dominoServiceClient.getServerName();
The second line adds the result of the getServerName() method to the "ViewBag" object which lets us refer to it from the view (the V in MVC).
Here's the "home" view, again the line in yellow is what I added:
Notice there's a reference to the new property I added to the viewbag.
All I needed to do then was press Run and here's what I saw in the browser:
Hey presto! Simple wasn't it!? I only had to write about three lines of code on each side - Domino and ASP.NET.
I went on to try out adding some more complicated methods to the Domino Web Service and making various other changes, but, as a proof of concept, the above solution worked well enough.
Although what I've shown is very simple it goes without saying that it gets more complicated when you start thinking about using it in a real world scenario. For starters you're probably going to want to authenticate users of the Web Service.
Is there any interest in this whole topic? I'll talk more about it if so. Or is it old news?
And what about SharePoint - would it be of interest if I covered how to connect to Domino from there?
No comments:
Post a Comment
Thank's!