How to: Create a workflow service that consumes an existing service contract
.NET Framework 4.5 features better integration between web services and workflows in the form of contract-first workflow development. The contract-first workflow development tool allows you to design the contract in code first. The tool then automatically generates an activity template in the toolbox for the operations in the contract.
Note
This topic provides step-by-step guidance on creating a contract-first workflow service. For more information about contract-first workflow service development, see Contract First Workflow Service Development.
Creating the workflow project
In Visual Studio, select File, New Project. Select the WCF node under the C# node in the Templates tree, and select the WCF Workflow Service Application template.
Name the new project
ContractFirst
and click Ok.
Creating the service contract
Right-click the project in Solution Explorer and select Add, New Item…. Select the Code node on the left, and the Class template on the right. Name the new class
IBookService
and click Ok.In the top of the code window that appears, add a
using
directive toSystem.ServiceModel
.using System.ServiceModel;
Change the sample class definition to the following interface definition.
[ServiceContract] public interface IBookService { [OperationContract] void Buy(string bookName); [OperationContract(IsOneWay=true)] void Checkout(); }
Build the project by pressing Ctrl+Shift+B.
Importing the service contract
Right-click the project in Solution Explorer and select Import Service Contract. Under <Current Project>, open all sub-nodes and select IBookService. Click OK.
A dialog will open, alerting you that the operation completed successfully, and that the generated activities will appear in the toolbox after you build the project. Click OK.
Build the project by pressing Ctrl+Shift+B, so that the imported activities will appear in the toolbox.
In Solution Explorer, open Service1.xamlx. The workflow service will appear in the designer.
Select the Sequence activity. In the Properties window, click the … button in the ImplementedContract property. In the Type Collection Editor window that appears, click the Type dropdown, and select the Browse for Types… entry. In the Browse and Select a .NET Type dialog, under <Current Project>, open all sub-nodes and select IBookService. Click OK. In the Type Collection Editor dialog, click OK.
Select and delete the ReceiveRequest and SendResponse activities.
From the toolbox, drag a Buy_ReceiveAndSendReply and a Checkout_Receive activity onto the Sequential Service activity.