Monday, March 29, 2010

Using Workflow as web service Part - 1

Hi All,

In last post, we saw how we can use web service in our workflow. In other word, we saw how we can consume web service in our workflow. So now in this post, we will perform the reverse operation. We will see how our workflow acts as a web service and how other applications can use the workflow as a web service.

It is not simple as creating a web service and just taking a reference from other application. It is much more than this. However Visual studio and workflow give us the great command to convert the entire workflow in web service. How can we use this feature? Well, we will see it later in this post.

First let us understand what all things are required for exposing workflow as web service. We will be using WebServiceInput and WebServiceOutput activities.

We must have at least one Input and at least one output activity in the workflow. We cannot have input activity without associating output activity and we cannot have output activity without associating it with some input activity.

Let us go ahead and deep dive into webserviceinput activity.

For Webserviceinput activity you need to set some properties and handle one event. Properties are as follows.

1) Interface Type: Get or Set the Interface data type for which we are going to expose our methods as web methods.

2) Is Activating: At least one of the activities must have this property set to true. This indicates that by calling this method, use can start the workflow. You can have more than one activity which has this property set true. However, if this is the case, then all these activities can start the workflow.

3) MethodName: Name of the method that can be exported as web method.

Out of these three properties, Is Activating is default set to false. All above properties must have values assigned otherwise be ready for validation errors.

Let us go ahead and now understand webserviceoutput activity.

Webserviceoutput activity must be bind with any of the webserviceinput activity for which you want to return the output. You must assign InputActivity name to the webserviceoutputactivity, otherwise validation error will be thrown.

If method returns void, then no need to bind the return parameter to the webserviceoutput, else you need to bind the appropriate return parameter to the webserviceoutputactivity.

More than one webserviceoutputactivity can be associated with one webserviceinputactivity. Reason being, let us say, we have one if else condition and in that we are processing some activities. Or we have parallel activities going on and it can take any of the branch path, then for each path ends, we need to return some values. Hence for each path end can be bind to the single input activity.

There is one more activity that we have to use in the workflow if we want to expose the workflow as web service.

Webservicefalut activity is same as webserviceoutputactivity and must be bind with the webserviceinputactivity. Only difference is that webservicefaultactivity is binded to the field or parameter of type Exception and to be set in Fault parameter of this property. This will ensure that if anything goes wrong, we need to send the exception or proper message to the calling client method.

Read Using Workflow as web service Part – 2 for further reading.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to