Article posted by Ambily.raj
on 1/6/2011 | Views: 9418 | Category: WWF
| Level: Intermediate | Points: 250
Workflow Foundation 4.0 is integrated with WCF and WPF. WF 4.0 uses WPF for activity designers and gives a very good support for custom activity designers with full WPF functionality. In this article we will look into the WCF integration to WF4.0.
When we create a new project, under the workflow project templates, we have the option to select the WCF Workflow Service Application.
Once, we create a WCF Workflow Service application, it will create a default WCF integrated workflow. Note that the extension of our new workflow file is not .xaml, it is .xamlx.
The default WCF workflow will look like
Custom WCF workflow
Now, let us add our own custom FlowChart workflow to the WCF workflow.
Drag and drop a receive activity
Specify the OperationName, which will act as the WCF operation or method name.
Set the CanCreateInstance property of the Receive activity. For running the workflow as WCF service, the current operation should be marked as CanCreateInstance=true.
4. Click on the Define clause against the Content. The Content Definition window will open. Define your method parameters here. In our sample, I defined a variable called Name, which I am passing to the operation GetMessage.
5. Now right click on the Receive activity and select Create SendReply option.
This will create the corresponding SendReply activity. Also, workflow will add a new variable for correlating both Receive and Send activities and will link both the activities. SendReply will act as the method which sends the result to the caller.
6. Again, click on the Define clause next to the Content of SendReply activity and define the result. Here I specified a message concatenating my input Name.
7. Added one Assign activity in between the Receive and Send to manipulate our data. Now, our Custom workflow is ready.
8. Let us verify it using the WCF Test client.
Here I passed the value Susan to Name parameter and observed the result as "Hello Mr/Ms. Susan". “Mr/Ms.” Clause is added to the Name by the Assign activity and the Hello is added by the Send activity.
Now, let us see, how we can use the workflow in a host application. Add the WCF workflow reference as the service reference to the host application. We can create the service client object and call the operation just like any other WCF service.
static void Main(string args)
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
Also, just like any other WCF service, we can browse the WCF workflow in browser.
Here, we discussed about the WCF integration with workflow foundation 4.0, how we can test a WCF workflow using WCF Test client and how we can call the WCF workflow from a host application.
If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.
Found interesting? Add this to: