Chapter 3 – Messaging and Transaction

MS WWF 4.0 Cook Book (Page 81) 02/21/2011, 06:02PM

Creating a pure WCF service

In IIS 7, create a new app pool, using .NET 4.0. Under the IIS default web site, create a new web application, using this new app pool, named “StockPriceService”.

Enter code as indicted by the book, and browse the SVC file.

In App_Code



If you get this error,
Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

you might need to run this command.


You can use WCF Test Client, which is located
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe

Add the service to the WCF Test Client by adding the URL:


Double click the GetPrice() to show details of this method. Click Invoke to invoke the method. It returns 94.85.

To understand WCF, you need to understand ABC:

A: Address.
because of address, the client knows where to find the service; in this case, the address is:……/StockService.svc

B: Binding.
because of binding, the service client knows how to use the service. There are many binding types such as basicHttpBinding, wsHttpBinding etc. Different serivces use different binding types. In this task, we use wsHttpBinding with the ServiceContract attribute to define the WCF contract.

C: Contract.
because of contract, the service client knows what content the service provides. In this task, we use the IstockService Interface that is decorated with the serviceContract attribute to define the WCF contract.

IIS captures the request, since it’s an SVC, so according to the httphandler mapping, IIS will use the appropriate handler to handle the WCF request.

Receiving and Replying to a WCF message

In this task we will create a workflow with Receive and SendReply activities. And run a workflow as a WCF service. The work flow will accpt two integers and return their sum to the caller. Use WCF Test Client to test it.

First, create a ***** WCF Workflow Service Application
– named ReceivedAndReply. This example combines WCF and Workflow!!!

Then you see this XAMLS Designer:

Add y and x as variable

Click ReceiveRequest, and click Content

Define Parameters, and capture the parameters values from the Variables (X/Y)

Configure SendResponse; add a parameter

Test it with WCF Test Client

X, and y are internal variables used throughout the workflow; xIn and yIn are parameters supplied by the caller.

ReceiveResponse – use xIn and yIn parameter to assign values to x and y
SendResponse – return a variable that is x + y

XAMLX is workflow designed specially for IIS. XAML can be converted to XAMLX by (1) removing all InArguments and (2) Rename XAML to XAMLX
Page 92.

In real applications, we should use Visual workflow instead of code workflow – there are too many things in code workflow you have to watch, while in visual workflow these details are hidden.

Sending and Receiving a reply yo a WCF message

We’re creating a WCF client workflow. The workflow will send a WCF request with 3 integer numbers to a WF service and receive a reply from the WCF service with the calculation result.

e.g., From WF Consol App (send 8, 1, 9 ) à WCF (calculate: (8 + 1) x 9 = 81) à WF Console App (receive 81 as answer) à print 81 in console

Create workflow console application, “SendAndReceive”. Use WCF test Client to find out the ABC’s.

Again, use WCF Test Client to find out the parameter names of the WCF service:

Now you can create a workflow that access the WCF since you have all the information you need.

Drag a SendAndReceiveReply activity.

Enter Send properties:

Add a variable “result”

Add Send Parameters: “Send” à “Content” à “…”

in ReceiveReplyForSend, define the incoming parameter name and save it to result (which is local to the workflow)

Add a print text at the bottom to print the result.

Ctrl + F5: (8 + 1) x 9 = 81

**** You can also add the WCF url as a service reference to the project. This appears to be much easier:

Build the project and you will see the GetData in the tool box.

Add a Sequence, GetData and print text: and add variables

Configure GetData:


(Page 104)


Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

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

Twitter picture

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

Facebook photo

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


Connecting to %s

%d bloggers like this: