Scripting with Web Services

To invoke a web service and use scripts to prepare data for the web service, you perform the tasks described in this topic.

First, add a Service Task onto the process diagram by dragging it from the tasks palette:

Then, in the General Properties sheet, set the Service Type to Web Service, then click Import WSDL. Locate your WSDL using one of the mechanisms provided (file location, URL, and so on), and select the webservice you want to invoke from the WSDL:

Looking in the Package Explorer, we can see the WSDL file under the Service Descriptors heading. You can open the WSDL by double-clicking the WSDL entry (or right-clicking on the WSDL entry and selecting OpenWith/WSDL Editor). Viewing the WSDL in the WSDL Editor, we can see what types the Web Service takes as parameters:

We can now create two Data Fields in the process of the appropriate types:

Then, from the Input To Service property sheet, map the requestInfo field to the RequestInfoType input of the Web Service by dragging the field name onto the parameter name, as shown in the diagram below:

The mapping will then be shown like this:

Then, repeat for the output of the Web Service:

Then, on the General property sheet, change the name of the task to something appropriate, for example, Call "Request" Web Service. Then, we have completed the Web Service task:

Now we need to prepare the data to go into the webservice and process the data that comes out of the web service. This can be done in scripts. To do this, drag two script tasks onto the Process Diagram before and after the Web Service call and name them appropriately:

The error markers in the figure above indicate that the scripts have not been written yet. In the General property sheet of the first script, set the Script Defined As property to JavaScript, and enter the script. First, we need to make the RequestInfo variable refer to an actual RequestInfo object by initializing it using the factory method (don’t forget to use the content assist to help. See Using Content Assist for more information). The following script is one example:

// Prepare Web Serice Call Request
requestInfo = com_amsbqa_linda01_xsd_define_types_types_Factory.createRequestInfoType();
requestInfo.correlationId = 123456;
requestInfo.password      = "Password!";
requestInfo.requestName   = "Search";
requestInfo.userName      = "Fred Blogs";

Something similar can be done in the script after the Web Service task. It is not necessary to make the flexpaySubscriberId field point to an object, because this will have already been done by the Web Service task. All that remains to do is process the values, for example:

// Process response from Web Service Call
if (null != flexpaySubscriberId)
{
    ban    = flexpaySubscriberId.ban;
    msisdn = flexpaySubscriberId.msisdn;
}