Silverlight 4: Consuming Workflow Service

Posted by: Mahesh Sabnis , on 10/4/2011, in Category Silverlight 2, 3, 4 and 5
Views: 82548
Abstract: This article demonstrates how to expose your Workflow based business processes as a Service and use a Browser client like Silverlight 4 to subscribe to it

While discussing Workflow 4.0 integration with WCF in one of my recent training programs, I was asked a question about consuming a WCF Workflow service in Silverlight. Initially I thought that it won’t be possible, because the “xamlx” extension of the WCF Workflow Service may not be accepted by the Silverlight client application. But it was an interesting question. So I decided to try it and it worked! I am sharing the solution in the form of this article.

The scenario we are discussing is as shown below:

silverlight workflow

The advantage of using the Workflow Services is that, since Workflow targets the business process applications, organization can create and publish these core processes based functionality and their client can subscribe to them. Since Silverlight applications provide a lightweight Rich Browser application development capability, its integration with Workflow Services provides additional capability for Rich UX and SOA based applications.

Creating Workflow 4.0 Service


Step 1: Open VS2010 and create blank solution, name it as ‘WF_WCF_Service’. In this solution, add a WCF Workflow Service Application, name it as ‘WF_WCF_Sample_Serv’. You will see the ‘Sequence’ activity with ‘Send’ and ‘SendReplyToReceive’.

Step 2: In this project, add a new class file, name it as ‘DataClasses.cs’ and add the following class in it:

silverlight-workflow-dataclass

Step 3: In the Workflow Designer, on the lower left corner, locate ‘Variables’ and delete the default ‘data’ variable and add a new ‘Employees’ variable of the type ‘EmployeeCollection’ as below:

workflow designer

Step 4: Change properties of the activity as below:

activity property name

The Workflow design will be as shown below:

workflow designer

Step 5: Publish the app on the IIS 7.5 web server. (Note: The Web site where the Workflow Service is hosted must have clientaccesspolicy.xml as shown below)

clientaccesspolicy

Creating The Silverlight Client Application

   
Step 1: In the same solution, add a new Silverlight client application and name it as ‘SL4_ClientApp’. Add the Workflow Service reference in this project.

Step 2: Open MainPage.xaml and add a DataGrid and Button in it. Make sure that the ‘AutoGeneratedColumns’ property of the DataGrid is set to ‘True’. The UI will be as below:

silverlight ui

Step 3: Write the following code in the Click event of the ‘Get Data’ Button:

image

The above code makes an asynchronous call to Workflow Service just like calling a normal WCF service.

Step 4: Run the application and click on the ‘Get Data’ button. The result will be as below:

image

Conclusion: The above facility helps any organization to expose their Workflow based business processes as
a Service and the Browser client like Silverlight can subscribe to it.

The entire source code of this article can be downloaded over here

Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Bruce on Thursday, October 6, 2011 12:41 AM
I had looked at using Workflow in a Silverlight app a while back and had given up on the idea. I have a lot of business processes that I would like to manage through a workflow approach. Your article gives me some hope.
I would like to communicate with you as I work on my app. and I could not get to your source code.
thanks!
Comment posted by Mahesh Sabnis on Friday, October 7, 2011 8:52 AM
Hi Bruce,
Thanks a lot.
Regards
Mahesh Sabnis
Comment posted by kamal on Tuesday, October 11, 2011 6:00 AM
Hi,

Can you give me some information/books/reference website for workflow because we have to use workflow in our Existing web application?

Thanks in advance...
Comment posted by Naitik Jani on Monday, December 26, 2011 3:38 AM
hi,

M naitik ...Jr.Software Developer working on WWF and WCF.. I want to learn WF in detail.
Comment posted by Mahesh Sabnis on Saturday, June 23, 2012 6:22 AM
Hi Kamal and Naitik,
The Packt publications has very nice books to learn Workflow.
Regarda
Mahesh Sabnis
Comment posted by Bernard on Wednesday, February 20, 2013 5:04 AM
where is the source code ?
Thanks!
Comment posted by Bernard on Wednesday, February 20, 2013 5:11 AM
where is the source code ?
Thanks!

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel