Silverlight 4: Consuming Workflow Service
Posted by: Mahesh Sabnis
in Category Silverlight 2, 3, 4 and 5
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:
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:
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:
Step 4: Change properties of the activity as below:
The Workflow design will be as shown below:
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)
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:
Step 3: Write the following code in the Click event of the ‘Get Data’ Button:
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:
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
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!
Was this article worth reading? Share it with fellow developers too. Thanks!
Mahesh Sabnis is a DotNetCurry author and a Microsoft MVP having over two decades of experience in IT education and development. He is a Microsoft Certified Trainer (MCT) since 2005 and has conducted various Corporate Training programs for .NET Technologies (all versions), and Front-end technologies like Angular and React. Follow him on twitter @maheshdotnet
or connect with him on LinkedIn