Incoming Web Service Requests Tutorial

From PresenceWiki
Revision as of 11:10, 21 July 2010 by Admin (Talk | contribs)

Jump to: navigation, search
Tutorial Pages > Incoming Web Service Requests Tutorial

This document gives a step-by-step guide to exposing a Presence Task as a Web Service.

1: Creating the Task

The first step is to create our Task. For the purposes of this demonstration we will create a Web Service that calculates the circumference of a circle given the radius. The Task to do this is very simple and comprises of:

  1. Start of Task Node
  2. Require Variable Node - ${radius}
  3. Set Variable Node - ${circumference}
  4. End of Task Node

The variable ${radius} will be an incoming parameter and ${circumference} will be an outgoing parameter.

To calculate the circumference we call the following function in our Set Variable Node (3):

&eval {"2 * ${radius} * PI"}

Here is a view of the Task, which can be downloaded here:

2: Creating the Web Service

Once a Task is created exposing it as a Web Service is extremely straight forward. First launch the Live Tasks Queue. Click on the third tab (Web Service Processes) and then drag the Task into the main table. You'll then be presented with the Web Service Properties Dialog:

  • The alias represents the name of the Operation that will be called and is auto-generated based on the Task name. Feel free to change this, or leave it as it is.
  • It's always a good idea to add documentation to the Web Service itself and to any parameters.
  • Make sure "Task is active" is checked and that "One Way" is not checked.
  • Copy the WSDL location to your clipboard as you will need this later when calling the Web Service.
  • Click the "Get Task Parameters" button to map the incoming and outgoing variables to Web service parameters:

Click okay to return to the Web Services properties screen. You can double click on the parameters to set the data type (which should be "double" for both parameters) and to add documentation.

This should be all you need to do - click Okay and you should see your Task in the Web Services list.

That's it!

Testing your Web Service

Now to test out our newly created Web Service. Create another new Task and drag a Web Service Call Node into the Task canvas. The first thing we need to do is set the WSDL location which you copied from the Web Service properties dialog. Click the "New" button, select "On the Internet" and enter the URL. This will be of the form:


Where [servername] is the hostname of a machine running the Presence HTTP Server, [port] is the port it is listening on - this is 80 by default unless you have changed it in the http.config file, and [wsdl_location] is the WSDL document location displayed on the Web Service Properties dialog.

So, here at the Presence development labs we have a server named "presenceserver" and this is the WSDL location we used for this project:

http://presenceserver/Presence/Web_Service_Tutorial.wsdl (don't click this - it won't work).

Note that the port is not included in the URL as 80 is the default port for HTTP requests and is therefore unnecessary.