AppFabric Apps (June 2011 CTP) – Simple Workflow App


In this post, I am going to walk you through creating a very simple AppFabric Application that includes invoking a Workflow.  Since I still don’t have access to the Labs environment(*hint Microsoft hint*) this demo will run in the local dev fabric.

The first step is to create a new project in Visual Studio 2010 and select AppFabric Application.

image

The User Interface for our application will be an ASP.Net Web App.  In order to add this Web App we need to click on the Add New Service label which you can find in the Design View when you double click the App.cs file.

Once the New Service dialog appears, we have the ability to select ASP.Net, provide a name for this application and then click OK.

image

Next we are going to perform the same actions to add a Workflow

image

 

This purpose of this simple application is to convert kilometers to miles and vice versa.  The Workflow will be used to determine which which calculation needs to take place i.e Miles –> Kilometers or Kilometers –> Miles.

When we add our Workflow service we will see a Sequential Service Activity with our Request and Response activities.

image

The first thing we are going to do is delete the existing data variable and add a few new ones.  The first one is called DistanceValue which is of type System.Double and the second is called DistanceMeasurement and it is of type System.String.  The final variable that we are going to set is called Result and will be used to return our converted result to our calling client.

image

 

Next we are going to change our OperationName.  We are going to set this to a value of ConvertDistance.

image

Since the default service that is generated by Visual Studio includes a single input parameter, we need to make some changes by clicking on the View parameter… label.

We want to set our input parameters to the variables that we previously created.

image

Next, we want to perform some logic by adding an If activity.  If the target DistanceMeasurement is equal to KM then we want to convert Miles to Kilometers otherwise we want to convert Kilometers to Miles.

image

With our Workflow logic in place we now want to deal with returning our response to our client.  In order to do so, we need to deal with our outbound parameters by clicking on the View parameter… label in our SendResponse activity.

 

image 

Once inside the Content Definition dialog, we can create a parameter called outResult and assign our variable Result to it.

image

The last step that we should do within our workflow is to set the ServiceContractName. I have changed this value to be {http://MiddlewareInTheCloud/SimpleWorkflow/}ConvertDistance

image

Since communication will occur with this Workflow via the AppFabric ServiceBus, we need to set our URI and related credentials.

image

Before we can set a Service reference to our Workflow Service, we need to expose our endpoint.  To do so we will pull down the no endpoints dropdown and select Add Endpoint.

 

image

We can now select ConvertDistance and provide a suitable Name.

image

With our endpoint set, we should be able to add a reference from our Web Application to our Workflow service.  We no longer need to do this by right mouse clicking on Project References and selecting Add Service Reference.

image

 

Instead we add a Service Reference from the Design View on our App.cs file.

image

Once we have selected Add Service Reference, we should be prompted with our ConvertDistance Workflow service.

image

Once added, we will now see a service reference called Import1.

image

Now that our references are set we can take a look at our Diagram that Visual Studio has generated for us by right mouse clicking on our App.cs file and selecting View Diagram.

image

 

With our Workflow built and configured, we now will focus on our ASP.Net Web app.  We will use a simple web form and call our Workflow from the code behind in our Web Form. Before we can do so, we need to add some controls to our Default.aspx page. In the markup of our Default.aspx webpage we are going to add the following:

image

Now we need to add an event handler for our btnSumbit button.  Within this code we are instantiating a proxy object for our Workflow service and passing in values from our ASP.Net Web Form.  We will then receive the result from our Workflow service and display it in a label control.

image

 

Testing

With our application now built it is time to test it out.  We will do so in the local development fabric and can load our Windows Azure compute emulator by typing CTRL + F5.  It will take a few minutes but eventually our Web Form will be displayed in our browser.

If we put in a value of 10 miles in our Distance to Convert field and click on our Button we will see that our workflow is called and returns a value of 16 Kilometers.

image

Conversely, if we set our Convert Distance to field to MI we will convert 16 Kilometers to 10 miles.

image

Conclusion

So as you can see wiring up Workflow services with ASP.Net web applications is pretty straight forward in AppFabric applications.  Once I get access to the Labs environment I will continue this post with deploying and managing this application in the cloud.

Advertisement

3 thoughts on “AppFabric Apps (June 2011 CTP) – Simple Workflow App

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s