Monthly Archives: February 2011

Chapter 2 – Hosting a WCF Service

MS WCF 4 Step by Step (Page 45) 02/27/2011, 10:36PM

A WCF service needs a hosting environment to run, Such as IIS. Hosting application must:
(1) start and stop the service
(2) Listening for request from a client application and directing them to the service.
(3) Sending any responses from the service back to the client application.

(Exectly what IIS is designed for!!!)

Service Endpoints

Host app makes a service available to clients by providing one or more endpoints to which clients can send requests.

End point has the following 3 information (ABC):

***Address of the service: it can be HTTP://….. Or other, depending on the transport mechanism.

***Binding supported by the service. Described how a client connect to the service and format of data, which includes:
Transport protocol, encoding format, security requirement, transactional requirement and reliability.

*** Contract implemeted by the service. A WCF contract is a interface.

Processing a Client Request

A service can respond to simultaneous client requests. Host application needs to ensure: security, reliability, transactional requirements etc. How is it done: WCF runtime environment provides a collection of channel objects
that can perform this processing.

A channel is responsible for handling one aspect of message processing. WCF provides channels that handle different tasks: encoding data, security, reliability, transactions. Together they’re called a channel stack. All messages passing between client and service go through each channel in a channel stack. E.g.:

Client ßà Channel ßà Channel ßà Channel ßà Channel ßà CF Service

** transport channel is always at the bottom; encoding channel is always at the top.

Advertisements

Chapter 1 – Introducing Windows Communication Foundation

MS WCF 4 Step by Step

Introduction to WCF; how to create, deploy and access a simple WCF service.

Web Services: XML + XML Schema
Web Service ßà Web Service Client using SOAP. A web service can publish a Web Service Description language (WSDL) which is also XML, that describe the messages the web service can accept and the structure of the response. A client application can use this information to determine how to communicate with the web service.

JSON – Javascript Object Notation. Completely language-independent. It organizes data into name/value pairs, or collections of values.

SOA – service oriented architecture

WCF provides a model with which you can implment services that conforms to many commonly-accepted styles and standards, such as SOAP, XML, JSON. Additionally, WCF supports many MS-specific technologies for building components, such as Enterprises and MSMQ.

Building a WCF service (P. 9)

VS 2010 has several WCF project templates that you can use to build WCF service.
In this exercise, we’re building a WVF service that provides the following information:
(1) products sold by AdvWorks
(2) obtain details of a specific product
(3) Query the current stock level of a product
(4) Modify the stock level of a product

We will make use of .NET 4.0 Entity Framework. Purpose: provide an object mapping between tables in a database and a set of objects that you can use in your applications and services. Generate an object model that you can use to query tables, and inset/update/delete data. A major adv: you can build your applications that are independent of the underlying database management system.

Create a new C# project using the Class Library template, name “ProductEntityModel”, solution name: ProductService

Dele Class1.cs file. Add a new item – ADO.NET Entity Data Model template to the project, name: ProductModel.edmx. You see the wizard.

Select generate from Database:

Add a new connection to the AdvWorks database

In the next screen, select the tables; click Finish. VS 2010 generates the entity model.

On the next scrren, it dispay the tables and the table fields <-> Coding property relationship:

Build the project, next, add a new web site to the solution. Right click solution à Add à Add new web site.
Add a WCF service webs ite

Note: you can create WCF service as part of a web site; or library; or a standalone application, or WF.

The structure of WCF service enables you to adopt a “contract-first” approach to develop. First you define the “interface”, or contract (that the actual service will implement), and then build a service that conforms to these contracts. Adv: you can concentrate on designing your service. Separate definition from its implementation.

The Interface file includes: [ServiceContract] and [DataContract].

— ServiceContract
— OperationContract
— OperationContract
— OperationContract
— DataContract
— DataMember
— DataMember
— DataMember

Update with your own DataContract

Define ServiceContract (method interfaces)

Implementing the Service

You must implement every method defined b the service contract in the WCF service. If you define additional methods that are not in the service contract, those methods will not be visible to the client app.

In the WCF web site, add a reference to the ProductsEntityModel (Project) and System.Data.Entity (.NET) – required from fetching data from entity model.

Rename Service.cs to ProductsService.cs

Add a namespace and an implementation class:

ListProducts method:

getProduct method:

Get current stock number of a specific product

Change stock level:

Build it.

Open Service.svc, update to the correct class and file name:

(Now you can “Browse to” service.svc and see the WCF service in IE)

*.SVC file is a apecial file that IIS use to recognize WCF service. If oyu don’t want the *.SVC file, you can add a serviceActivation tag in web.congif. But you still need to use *.svc in your URL. Can’t really see the benefits. Just add more confusion!

Creating a WCF Client application

VS 2010 can use the WCF metadata (WSDL) to create a proxy class
that the client can use to connect and consume the service.

Add a new project – Console Application to your solution, name: ProductsClient.

For this project, add a reference to System.ServiceModel.

Add the WCF service as a Service Reference to the ProductsClient project. Click Discover and it will display the WCF service.

*** The Discover button is to display all WCF services that are in the same solution. Give the namespace “ProductsService”. Now the WCF Service is a service reference in the console application:

Reference.cs is the Proxy Class:

Open console app’s app.config and you see the WCF info (ABC etc.) has been added when the service ref is added.

Add these two usings in the Program.cs, in console app.

First, create a proxy object:

To configure startup project(s) in a solution:

Set the WCF service and the client console app to start:

Right click the WCF service, “Start Options”.

Set to “Don’t open a page” so VS 2010 don’t open an IE window.


Full client code:

Deploying WCF Service to IIS

We want to deploy the WCE service to an IIS, and then reconfigure the client to connect to IIS.

Right click WCF service, Publish web site:

Point to local IIS; default web site, create new web application.

Name is “ProductsService” and then Open. Click OK:

*** Configure the new WCF web app to use an application pool that uses .NET 4.0, or else it won’t work.
*** If still not working, make sure the WCF service’s application pool’s identity can access the Database!!!!!

end of chaper 1

Chapter 1 – Introducing Windows Communication Foundation

MS WCF 4 Step by Step

Introduction to WCF; how to create, deploy and access a simple WCF service.

Web Services: XML + XML Schema
Web Service ßà Web Service Client using SOAP. A web service can publish a Web Service Description language (WSDL) which is also XML, that describe the messages the web service can accept and the structure of the response. A client application can use this information to determine how to communicate with the web service.

JSON – Javascript Object Notation. Completely language-independent. It organizes data into name/value pairs, or collections of values.

SOA – service oriented architecture

WCF provides a model with which you can implment services that conforms to many commonly-accepted styles and standards, such as SOAP, XML, JSON. Additionally, WCF supports many MS-specific technologies for building components, such as Enterprises and MSMQ.

Building a WCF service (P. 9)

VS 2010 has several WCF project templates that you can use to build WCF service.
In this exercise, we’re building a WVF service that provides the following information:
(1) products sold by AdvWorks
(2) obtain details of a specific product
(3) Query the current stock level of a product
(4) Modify the stock level of a product

We will make use of .NET 4.0 Entity Framework. Purpose: provide an object mapping between tables in a database and a set of objects that you can use in your applications and services. Generate an object model that you can use to query tables, and inset/update/delete data. A major adv: you can build your applications that are independent of the underlying database management system.

Create a new C# project using the Class Library template, name “ProductEntityModel”, solution name: ProductService

Dele Class1.cs file. Add a new item – ADO.NET Entity Data Model template to the project, name: ProductModel.edmx. You see the wizard.

Select generate from Database:

Add a new connection to the AdvWorks database

In the next screen, select the tables; click Finish. VS 2010 generates the entity model.

On the next scrren, it dispay the tables and the table fields <-> Coding property relationship:

Build the project, next, add a new web site to the solution. Right click solution à Add à Add new web site.
Add a WCF service webs ite

Note: you can create WCF service as part of a web site; or library; or a standalone application, or WF.

The structure of WCF service enables you to adopt a “contract-first” approach to develop. First you define the “interface”, or contract (that the actual service will implement), and then build a service that conforms to these contracts. Adv: you can concentrate on designing your service. Separate definition from its implementation.

The Interface file includes: [ServiceContract] and [DataContract].

— ServiceContract
— OperationContract
— OperationContract
— OperationContract
— DataContract
— DataMember
— DataMember
— DataMember

Update with your own DataContract

Define ServiceContract (method interfaces)

Implementing the Service

You must implement every method defined b the service contract in the WCF service. If you define additional methods that are not in the service contract, those methods will not be visible to the client app.

In the WCF web site, add a reference to the ProductsEntityModel (Project) and System.Data.Entity (.NET) – required from fetching data from entity model.

Rename Service.cs to ProductsService.cs

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.

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:

Result:

(Page 104)

 

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.

Chapter 2 – Built-in Flow Control Activities (Part 2)

MS WFF 4.0 Cookbook (P.63) 02/17/2011, 10:01PM

Using the Switch<T> activity in Sequence workflow

New Workflow Console application, “UsingSwitchActivityInSequenceWorkflow”.

Switch….Case….Case….

Using the FlowSwitch<T> Activity

New Workflow Console Application, “UsingFlowSwitchActivity”.

Drag a flowchart to WF Designer, and a FlowSwitch. You will be asked to select a type, select String

For erach of the case, define the case value, and whether it’s a default value

Clicko in the FlowSwitch and define the “Expression” (or default input value)

The “Type Selector” is just a way to let you pick which data type this FlowSwitch will be working on.

If you have only two decision path (True/False, Yes/No), then use FlowDecision; else, use FlowSwitch.

Using the Parallel Activity

New Workflow Console app, “UsingParellelActivity”.
Drag a Parallel ontoWF Designer.


You can drag two or more Sequences into the Parrall.

Multiple sequences can run at the same time. Still on single thread.

Results:

Using the ParallelForEach<T> Activity

ParallelForEach<T> is a special version of ForEach<T> activity. Difference:

e.g., integer array {1, 2, 3}

ForEach: 1 à 2 à 3
ParallelForEach: process 1 and 2 and 3 at the same time.

Using the Pick Activity

Similar to Listen activity in WF3. Will execute one of its parallel subactivities, and only one of its activities will be executed before the Pick activity completes.

New Workflow Console Application, “UsingPickActivity”.

Drag a Pick activity and two activities (Branch) automatically added:

Both branch will execute parallel, but if Branch 1 compeltes first, Branch 2 will be cancelled.

Chapter 2 – Built-in Flow Control Activities (Part 1)

MS WWF 4.0 Cookbook (P. 41)

Flow is the center of WorkFlow. How to control the Flow
is what we will see in this chapter. In WF4 we have many concepts (simlar to C#) such as if-else, foreach, switch, try-catch and so on.

WF4 supports (1) Sequence workflow and (2) flowchart workflow. State machine workflow will be available in .NET 4.5.

Using the Foreach Activity

Create a workflow console application, “UsingForeachActivity”.

Add a class: Person.CS. Name, Age, Initializer, and ToString()

Build the solution, and in WF Designer, import the UsingForEachActivity namespace.

Declare a variable of List of Person class (List<Person>)

Select List<T>, then browse the list type, select Person.

In the end: people is a generic list of Person objects.

Enter this code in the default expression of the variable people. (to initialize?)
Currently, we can only use VB Expressions.


inside Sequence, add a ForEach activity. Type of Argument is UsingForEachActivity.Person.

A Number guessing game in Sequence

New Workflow Console app, named “GuessnumberGameInSequence”.

Add c ode file, build it, and it will be available in ToolBox.

Note: Difference between CodeActivity and NativeActivity

useful in creating custom code and activities. When you create your own code, you can inherit either one.

CodeActivity:
(1) provides an Execute method that canbe overwritten to have your implementation. Provide access to tracking, variables and argumnets.
(2) use CodeActivity for simple custom activities
(3) Use CodeActivity for Sync activities.
(4) Use when you need to execute a single pulse of execution.
(5) Use when you do not need to schedule other activities.
(6) Use when you do not need to use advanced WF runtime features.

NativeActivity:
(1) With all features of CodeActivity, plus (a) abort activity execution, (b) cancel child activity execution, (c) schedule activities, (d) use bookmarks, (d) use activity actions and functions.
(2) Complex custom activities
(3) for long running custom activities
(4) when you need to execute multiple pulses
(5) when you have to schedule other activities
(6) when you need to used advanced WF runtime features.

Unless needed, use CodeActivity.

A Number Guessing Game using a FlowChart

Create the same game using flowchart. Will demonstrate the usage of the FlowDecision activity.

new Workflow console application, “GuessNumberGameInFlowChart”. Add a Code file, ReadNumberActivity.CS (same as previous practice), build the code, and it’s available in the Toolbox.

Drag a FlowChart to WF Designer.

Start dragging activities to the Designer. There are connection points in each object and you can drag and connect them.

Drag a FlowDecision when you need to make a decision:


Each FlowDecisin has a Condition to decide which way it should go

This is very powerful yet easy and very intuitive….

Running:


So two ways:
(1) Sequence with IF-Else
(2) FlowChart with FlowDecision.

Which one to use????? If we have a lot of backward transitions, then use FlowChart.

Using InvokeMethod Activity

Use this method to invoke various kinds of activities. Invoke a method in a class file.

Create Workflow Console Application “UsinginvokeMethodActivityInCode”.

Cretae a class TestClass.cs with some methods in it:

Here is a simpler example:
A simple class file with a VOID method

Drag a InvokeMethod activity, and set propertyies

Run it.

Another sample (with parameters)

Since this method accepts two parameters, set up parameters, run it

Another one – with parameters, and with a return type


(Page 60)

Another one – method with in-parameters, and a out (reference) parameter

Everything the same, except add resultVar as a In/Out variable

Another example: generic type (meaning any type)

In GenericTypeArgument, enter all known types:

InvokeMethod a static method:


Chapter 2 – Built-in Flow Control Activities (Part 2)

MS WFF 4.0 Cookbook (P.63) 02/17/2011, 10:01PM

Using the Switch<T> activity in Sequence workflow

New Workflow Console application, “UsingSwitchActivityInSequenceWorkflow”.

Switch….Case….Case….

Chapter 2 – Built-in Flow Control Activities (Prart 1)

MS WWF 4.0 Cookbook (P. 41) 02/17/2011, 06:40PM

Flow is the center of WorkFlow. How to conotrol the Flow
is what we will see in this chapter. In WF4 we have many concepts (simlar to C#) such as if-else, foreach, switch, try-catch and so on.

WF4 supports (1) Sequence workflow and (2) flowchart workflow. State machine workflow will be available in .NET 4.5.

Using the Foreach Activity

Create a workflow consol application, “UsingForeachActivity”.

Add a class: Person.CS. Name, Age, Initializer, and ToString()

Build the solution, and in WF Designer, import the UsingForEachActivity namespace.

Declare a variable of List of Person class (List<Person>)

Select List<T>, then browse the list type, select Person.

In the end: people is a generic list of Person objects.

Enter this code in the default expression of the variable people. (to initialize?)
Currently, we can only use VB Expressions.


inside Sequence, add a ForEach activity. Type of Argument is UsingForEachActivity.Person.

A Number guessing game in Sequence

New Workflow Console app, named “GuessnumberGameInSequence”.

Add c ode file, build it, and it will be available in ToolBox.

Note: Difference between CodeActivity and NativeActivity

useful in creating custom code and activities. When you create your own code, you can inherit either one.

CodeActivity:
(1) provides an Execute method that canbe overwritten to have your implementation. Provide access to tracking, variables and argumnets.
(2) use CodeActivity for simple custom activities
(3) Use CodeActivity for Sync activities.
(4) Use when you need to execute a single pulse of execution.
(5) Use when you do not need to schedule other activities.
(6) Use when you do not need to use advanced WF runtime features.

NativeActivity:
(1) With all features of CodeActivity, plus (a) abort activity execution, (b) cancel child activity execution, (c) schedule activities, (d) use bookmarks, (d) use activity actions and functions.
(2) Complex custom activities
(3) for long running custom activities
(4) when you need to execute multiple pulses
(5) when you have to schedule other activities
(6) when you need to used advanced WF runtime features.

Unless needed, use CodeActivity.

A Number Guessing Game using a FlowChart

Create the same game using flowchart. Will demonstrate the usage of the FlowDecision activity.

new Workflow console application, “GuessNumberGameInFlowChart”. Add a Code file, ReadNumberActivity.CS (same as previous practice), build the code, and it’s available in the Toolbox.

Drag a FlowChart to WF Designer.

Start dragging activities to the Designer. There are connection points in each object and you can drag and connect them.

Drag a FlowDecision when you need to make a decision:


Each FlowDecisin has a Condition to decide which way it should go

This is very powerful yet easy and very intuitive….

Running:


So two ways:
(1) Sequence with IF-Else
(2) FlowChart with FlowDecision.

Which one to use????? If we have a lot of backward transitions, then use FlowChart.

Using InvokeMethod Activity

Use this method to invoke various kinds of activities. Invoke a method in a class file.

Create Workflow Console Application “UsinginvokeMethodActivityInCode”.

Cretae a class TestClass.cs with some methods in it:

Here is a simpler example:
A simple class file with a VOID method

Drag a InvokeMethod activity, and set propertyies

Run it.

Another sample (with parameters)

Since this method accepts two parameters, set up parameters, run it

Another one – with parameters, and with a return type


(Page 60)

Another one – method with in-parameters, and a out (reference) parameter

Everything the same, except add resultVar as a In/Out variable

Another example: generic type (meaning any type)

In GenericTypeArgument, enter all known types:

InvokeMethod a static method:


Chapter 1 – Workflow Program (Part 2)

MS WWF 4.0 Cookbook

Customizing a MyReasLine activity with Bookmark

To pass data from the caller into the workflow when it’s executing – Using BOOKMARK

New workflow console application,”UseBookMark”, next add a code file and name the file MyReasLineActivity.

Edit the MyReasLineActivity.cs. This will be compiled as a toolbox that can be dragged into WF Designer. (function: read line input and pass it to executing workflow)

Go a build solution and the MyReadLine will show up in the toolbox:

WF Designer and add one variable and one argumnet


Click on MyReadLine, and enter the values:

Executing…. (during the execution, get input from caller, and then pass the input inside the workflow, keep processing, and end)

Converting a WF Program instance to XAML

In real applications, we’d like to write and test WF programs in imperative code, while storing, running and transmitting workflow as an XAML string or file. In this task, we will convert a WF program instance to an XAML string.

New workflow consol application, “ConvertWFInstancetoXAML”, delete the Workflow1.xaml. Open Program.CS, enter the codes:

Loading up a WF Program from an XAML File

Run a WF program by loading it from an XAML file.

New Workflow Consol application, “LoadUpWorkFlowFromXAML”. A simple workflow. Go to the source of the WF Designer, copy the XAML source, and save it as a *.XAML file in a different folder, such as C:\WF.XAML. Then delete the workflow1.xaml. This practice is to test whether we can load and run a xaml file that’s not part of a project.


Code to load and invoke the workflow. This can load an run any arbitery XAML workflows. Should be very useful.

Testing a WF Program with a Unit test FrameWork

Create a test project to do unit testing for a WF program

Add a Test Project to solution, and name the project as “UnitTestForWFProgram”.


Add a new item à Workflow à Activity

Add an argumnet; WF designer:

Create unit test Code: (UnitTest1.CS) Ctrl + F5 wouold start the test. It compare the output message with the string provided and see if it’s the same.

in the preceding code, [TestClass] indicates it is a unit test class, whereas [TestMethod] indicates a test method. When the Test Project runs, the test method wll be executed automatically.

Debugging a WF Program

how to debug a WF Program

Create new Workflow Console Application, named “DebugWFProgram”

Program.CS

Click on an Activity to insert a BreakPoint:

You can also debug the source of XAML code: