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

StockService.svc

web.config


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

you might need to run this command.

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis
–iru

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:

Done:

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.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: