Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

.NET

Windows Workflow Foundation and Web Services


Workflow as a Web Service

Using the WebServiceInput, WebServiceOutput, and WebServiceFault activities, you can expose your workflow as a web service. This has some advantages, especially within SOA environments and when deploying a Windows-based application instead of a web-based application. In this section, I present an example of a simple workflow that's exposed as a web service. First, create a VB Sequential Workflow Library called "VBAsWebServiceSequentialLibrary."

Make sure you select Sequential Workflow Library. Change the name of the Workflow1.vb file to "WorkflowAsService.vb." Open the workflow file (WorkflowAsService.vb) and view the code. Add Public ValueEntered As Integer to the workflow class declaration. This variable holds the inputted value and allows manipulation of it. Next, you must define the interface that will be exposed. An interface is what other applications wanting to use this web service will see. It defines any methods or properties that other applications can use to interact with the web service, and is a core OOP concept. To define the interface, add the following:

Public Interface IWorkflowAsWebService
    Function AcceptValue(ByVal InputValue As 
                       Integer) As Integer
End Interface

Any application wanting to use this web service will see only the AcceptValue method, and will see that this method expects a parameter that is of type Integer. Next, view the designer and add a WebServiceInput activity to the workflow. Leave the default name, but click the ellipse next to Interface Type. This displays a window that lets you pick a .NET Type. You want to select the interface that was just defined. You can do this by clicking the Current Project folder on the left and selecting the defined interface, as in Figure 5.

[Click image to view at full size]

Figure 5: Select the newly defined IWorkflowAsService interface.

Set IsActivating to True, because the first WebServiceInput activity within a workflow must have the IsActivating property set to True. From the drop-down list next to the Method Name property, choose AcceptValue. This links the call to the WebServiceInput activity to the interface. When an application using this web service makes a call to this web service and executes AcceptValue, the workflow engine will know to call this WebServiceInput activity. Finally, from the drop-down next to InputValue under the parameters, select IntInputValue. Click the Promote Bindable Properties link at the bottom of the Properties window. Click the ellipse next to the InputValue property and choose ValueEntered from the Bind Properties dialog box. This ties the value passed in as a parameter to AcceptValue to the ValueEntered variable defined within the workflow. The properties of the WebServiceInput activity look like Figure 6.

[Click image to view at full size]

Figure 6: Properties for the WebServiceInput activity.

Add a WebServiceOutput activity to the workflow. Leave the name as the default. Use the drop-down next to InputActivityName to select WebServiceInputActivity1. This property ties the two activities together, so the input activity is receiving information, the output is sending the information, and it's the same information. Click the Promote Bindable Properties link at the bottom of the Properties window. Click the ellipse next to the Return Value property and choose ValueEntered from the Bind Properties dialog box. Again, this ties the value returning to the application that calls this web service to the variable declared within this class.

Next, click GenerateHandlers at the bottom of the Properties window. This generates code to be executed when the activity is executed. When the sub is created, add:

IntInputValue = IntInputValue + 10

This simply adds 10 to the value provided by the calling application. Now the workflow is complete. The workflow will accept a value, add 10 to that value, and return it to the calling application. This simple example shows how you can use a workflow as a web service.

The final step to make a workflow into a web service is to publish the workflow as a web service. To do this, right-click the project name within the Solution Explorer and choose Publish as Web Service. A solution is created within the Solution Explorer, and all the necessary files are also created. To view the created web service, right-click the file with the .asmx extension (VBAsWebServiceSequentialLibrary.WorkflowAsService_Web-Service.asmx) and choose View In Browser. This opens the .asmx file in the browser. Click the AcceptValue link to test the AcceptValue method. Enter 10 as the InputValue and click the Invoke button. The result of 20 appears in the XML file. This shows the workflow working as a web service.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.