Connecting to a Workflow Service from LightSwitch Part 2


The second part of this topic discusses how to deploy the Workflow service that was implemented in Part 1, how to create a proxy used in either a console application or test project and how to create a proxy used by a LightSwitch application.

Deploy the Workflow service

For the following task, start Visual Studio 2010 and a Visual Studio command prompt window with administrator privileges. You need sufficient rights to publish to IIS as well as run other tasks, such as iisreset, you may need during debugging.

I am running on Windows 7 with IIS installed on the same machine. If you’re running on Windows Server 2008 or deploying to IIS running on a different machine, your steps may be slightly different, yet have enough similarity to follow along here.

In the VS 2010 command prompt window, navigate to the inetpub\wwwroot directory and create a folder to publish the workflow service. I named my folder WFServiceOrderProc

Next, go to the VS 2010 solution and right mouse click on the workflow service project, ServiceLibrary. Select Publish… in the pop up context menu to display the Publish Web dialog.:

Select File System as the publish method in the Publish Web dialog. Specify the target folder you created in the VS 2010 command prompt window.


Click Publish to deploy the workflow service to IIS.

Next, start IIS Manager. One way to quickly start IIS Manager is by entering INETMGR in the search programs and files textbox from start programs.

In IIS Manager, change the WFServiceOrderProc from a folder to a web application.


Next, in the IIS category, double click the Directory Browsing icon to display the Directory Browsing properties. In the right panel, click enable to enable directory browsing.


Next, right mouse click the WFServiceProc -> Manage Application -> Browse


A browser similar to this should start:


Click the OrderProcessing.xamlx link should display this:


Copy and paste to a temporary file the line starting with SVCUTIL.EXE. Change the machine name LAPTOP1 (my machine) to local host.

svcutil.exe http://localhost/WFServiceOrderProc/OrderProcessing.xamlx?wsdl

With these steps completed, you have the workflow service deployed and verified IIS can run it. The next step is creating a client project to run and test the workflow service.

Create a Test Project and Proxy

Return to Visual Studio and create a new project using the Test template.


In the Visual Studio command prompt, navigate to the Test project folder and run the SVCUTIL command.


The SVCUTIL command will connect to the workflow service, read the metadata, and create a proxy called OrderProcessing.cs.

Add the OrderProcessing.cs file to the Test project.

Rename the file UnitTest1.cs to TestCalcShippingWorkFlow.cs

Add the following assembly references to the test project:

· System.Runtime.Serialization

· System.Runtime.ServiceModel

Next implement a constructor to create the proxy and implement workflow service tests.

Below are the constructor and one of the test implementations. You can find all the tests in the zip file that’s part of this posting.



Create a Proxy for LightSwitch

Because LightSwitch is a Silverlight application, the proxy created above will not work in a LightSwitch solution. You need to implement the proxy using async methods and use different assembly references for a LightSwitch solutions.

Creating this workflow service proxy is very similar to creating the proxy to a WCF service I described in an earlier blog post. To ensure we’re on the same page, I’ll explain the steps again here.

Open a light switch solution. I called mine OrderHeaderTest. At this point, select Attach to External Database and connect to the AdventureWorks database. Use the wizard to connect the SalesOrderHeaders table. It’s not important at this point to do more in the LightSwitch project. I’ll describe more about the screens and code behind in the next post.

Add a new project to the OrderHeaderTest solution using the Silverlight Class library template. Rename the Class1.cs file to OrderProcessing.cs.

In the VS 2010 command prompt, navigate to the folder containing the OrderProcessLib solution and use the SLsvcutil.exe to create a Silverlight proxy. On my machine, the SLsvcutil utility is in this path:

“c:\Program files (x86)\Microsoft SDKs\Silverlight\v4.0\Tools\SLsvcutil.exe” http://localhost/WFServiceOrderProc/OrderProcessing.xamlx?wsdl


Add the generated proxy, OrderProcessing.cs, to your OrderProcessLib project.

Implement the LightSwitch Proxy

The class constructor creates the proxy, an OrderProcessingRequest and OrderProcessingResponse objects. (Lines 20 – 29)

The constructor initializes a AutoResetEvent object used to signal completion of the async callback method, _proxy_ProcessOrderCompleted(). (Line 24)

Finally the constructor wires up the async callback method. (Line 31)


The proxy’s method to invoke the workflow is straightforward. It takes three parameters which it copies to the OrderProcessingRequest object. (Lines 42 – 44). In then evokes an async call to the workflow service (line 46) and waits for the completion of the callback (line 48). On completion, the proxy returns the value of the calculated shipping charge (line 50).


That completes the deployment of the workflow service, testing the service, and implementing the proxy for the LightSwitch application.

The next blog post will describe using the workflow service from the LightSwitch project.


This entry was posted in LightSwitch. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *