Connecting to a Workflow Service from LightSwitch Part 2

Overview

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.

clip_image002

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.

clip_image003

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.

clip_image004

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

clip_image005

A browser similar to this should start:

clip_image006

Click the OrderProcessing.xamlx link should display this:

clip_image008

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.

clip_image010

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

clip_image012

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.

clip_image014

 

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

clip_image016

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)

clip_image018

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).

clip_image020

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.

2 Responses to Connecting to a Workflow Service from LightSwitch Part 2

  1. 365 bet john says:

    Howdy this is kind of of off topic but I was wondering if blogs use
    WYSIWYG editors or if you have to manually
    code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

    • Dan says:

      First, thanks for reading my blog and asking!

      I use Microsoft Live to make postings to my blog.

      I find it does mostly what I need to do.

      I usually write a blog posting first in Word. I think Word’s spell and grammar check are better than Lives, and it’s easier to write a document in saving to disk, making revisions, and sending the document to someone for a quick review and comment before posting for the world to see.

      Once I’m ready to post, I just copy and paste from Word in Live. There are usually a few tweaks need in layout, font size, and image sizing. And if you’re posting code, picking the ‘right’ plugin (which ever works best for you.) is the trickier part.

      Hopefully that helps a little.

      If you have more questions or other questions, don’t hesitate to ask.

Leave a Reply

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


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>