Welcome to MSDN Blogs Sign in | Join | Help

Calling a Windows Communication Foundation (WCF) - Service from a Workflow

When using WinFX Feb CTP and building workflows based on it after a while the question arises: How to integrate Windows Communication Foundation (WCF) based services with Windows Workflow Foundation (WF)?

Looking at the available activities coming with WF there is one which seems to be a good candidate: InvokeWebService.

So I built a WCF Service with a data contract (separated from the service implementation in an own assembly named OrderContract, defining two classes: Order and OrderItem which is used by Order) and hosted the service on IIS. This should work well with the InvokeWebService-activity from WF. The service provides one method submitOrder(OrderContract.Order).

Next step was to implement a simple sequential workflow containing one activity to invoke my WCF service.
I added a private member of type OrderContract.Order to the workflow cause I want to link that member with the parameter needed
by the WCF service method submitOrder(OrderContract.Order).

Adding the InvokeWebService-activity to the WF starts a wizard which tells me to specify the URL of the service. I specify the URL and choose a name for the Web Reference. Done this I specify the method of the service to invoke by the activity and its properties (two for the result and one for the parameter of type OrderContract.Order).

Surprise: The property window doesn't allow me to assign my private member of type OrderContract.Order to the parameter-property of the service's method.
Reason: The wizard generated a proxy (including the data contract information) for the service in a namespace with the name of
the Web Reference. So for the WF activity the private member and the property are of different type cause they reside in different namespaces.
Solution: Renamed the Web Reference so that it has the same name as the assembly containing the data contract (OrderContract).

That results in identical namespaces and I can assign the private member to the property.

The better approach is to generate a proxy client for the WCF service using the svcutil-utility because it enforces the WCF paradigm of separating business logic and transport. The proxy client can be used in a WF code activity. The service configuration information for the client has to be added to configuration file of the application hosting the WF.

Attached you can find the two solutions I used for the scenario with the InvokeWebService-activity.

Published Thursday, March 23, 2006 5:33 PM by anderl

Attachment(s): WFWCFIntegration.zip

Comments

# re: Integration of WF and WCF

The second possibility, maybe extended to be a first class activity, seems like a better option. Doesn't forcing the WCF implementation to use the web service protocol somewhat defeat part of the purpose of WCF? You now have a hard-coded client that expects a web service protocol.
Thursday, March 23, 2006 3:02 PM by SpoonsJTD

# re: Integration of WF and WCF

Totally agree with you. WCF is an abstraction layer above several communication technologies including Web Services. Following the WCF paradigm of separating business code from transportation details results definitely in either using a WF code activity or writing a custom activity which forces that pattern.
But from the WF perspective I just want to call a service; I know that this service is hosted on IIS and I can obtain a WSDL from the URL. So the WF minded conclusion might be to use the activity 'InvokeWebService' because the endpoint has an http-syntax.
Thursday, March 23, 2006 6:29 PM by anderl
Anonymous comments are disabled
 
Page view tracker