Click here to Skip to main content
Click here to Skip to main content

Exposing Windows WorkFlow as Web services

By , 9 May 2008
Rate this:
Please Sign up or sign in to vote.

Introduction

To start with I am posting an example which enable developer to expose the WF as Web Service,

so that the Client from any domain can use this work flow capability as a service.

The other options that are available with windows work flow and web servicein VS 2008 are:

1) Windows Work flow can consume a Webservices.

2) By Using "WebServiceFaultActivity" from the toolbox, we can emit fault message to the client

post exception handling. In my next articles I would be covering the same.

Background

(Optional) Is there any background to this article that may be useful such as an introduction to the basic ideas presented?

Using the code

A brief description of how to use the article or code. The class names, the methods and properties, any tricks or tips.

Blocks of code should be set as style "Formatted" like this:

			First Create a Empty Project in Visual Studio 2008, name it “PrabhjotWFasWs”.


		

fig1.JPG

Fig 1

Add a class "Mathservice.cs" to our project, and declare a Interface name "MathService",

with a Method name as "DivideNumber" inside the same file.

fig2.JPG

Fig 2.

Defining Interface is mandatory, as here the Interface MathService, with a method,will get associated with

the "webServiceInput" activity from the tool box),in the Workflow. This Interface method will take the shape

of "Webmethod" from Webservice point of view and the "WebserviceInput" acitivity would behave as a gate

for input parameter for the Work flow for getting activated and initialized.

Therefore probably this is first time,we are saying goodbye to Dictionary Object as input parameter.

Next step is to add a workflow type "sequentialWorkFlow with codeseparation", into our project and

name it "WorkflowasService.xoml".

Then drag three activities in the same order- WebserviceInput,codeactivity, WebServiceOutput.

Now we will set the properties of the activities. Select the WebserviceInput shape and press f4,

to view the property window.

In the Property window of the Webserviceinput activity, we click the eclipse next to interfacetype selection option,

kindly select our interface name as "MathService", and select Method name as "DivideNumber", post this we

would expend the parameters tree in the same property window.It will expand to "Dividend" and "Divisor" parameters.

As shown in Fig 3 and Fig 4

fig3.JPG

fig3

fig4.JPG

Fig4

Next select the eclipse associated with the "Dividend" parameter. In the Pop Out window select the option

"Bind to a new Member", assign "A", to new member name and also select a "create Property" option, as shown in Fig. 5

This will result in creation of a declarative property in the view code of the workflow.

fig5.JPG

Fig 5

Similarly for the another parameter "Divisor", again select the "Bind to a new member",

assign "B", to New member name, and select the create Property option as shown in Fig 6.

fig6.JPG

Fig 6

Make sure that in the property window, we change the property of "IsActivating" to "true" .Similarly we Select the

Webserviceoutputactivity1 shape and open its property windows, We will create a new Property "C",and bind it to

the Return Value Property as shown in Fig.7 Plus make sure we assign WebserviceInputactivity1 to the InputActivityname property.

Each webserviceoutput activity would be linked with one webserviceinput activity. Fig 7

fig7.JPG

Fig7

Now we have to add the action the code Activity, where the real division activity takes place. For which double

click the codeactivity shape in the Workflow and type this code c=a/b. fig 8

fig8.JPG

Fig 8

Now we are done all you have to do is to first Build the project and the right click on the project

name in the Solution explorer and click on “Publish as webservice”. Fig 9.

fig9.JPG

Fig 9

Once you are done will see that a new project file is created in the same solution explorer with a .asmx file,

set it as startup project and run the project you will get a familiar Web service testing page. Fig 10 and Fig 11.

fig10.JPG

Fig 10

fig11.JPG

Fig 11

Use the "var" button to to wrap Variable or class names in <code> tags like this.

Points of Interest

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?

History

Keep a running update of any changes or improvements you've made here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Prabhjot Singh Bakshi
President www.elearningfromhome.com
India India
based out of Dubai(resident visa) and India(Citizen) , I am Corporate and Microsoft Certified Trainer on .net3.5, VS 2010, .net 4.0 and Biztalk Server 2009.
 
My client list- IBMCap Gemini), Intel,Logica,Mcafee,KPIT,Wipro,Accenture,Royal bank of Scotland,SMTC(Dubai),Patni,CSI, IEEE, Delta,Ness,Mphasis,SAIC,Kanbay(hyd), Polaris, ICICI techProcess, 3i Infotech,Scope, HCL,SunGard, Microsoft India, Virtusa Hyd,Solid Solution exact pvt. Ltd.

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberlohithrao26-Mar-13 20:27 
GeneralMy vote of 1 PinmemberMember 361671130-Aug-10 23:56 
Generalpublish workflow programatically Pinmemberaidin_dotnet31-Dec-09 7:55 
Questionerror PinmemberNarendra Reddy Vajrala9-Mar-09 3:20 
GeneralGood Article PinmemberNarendra Reddy Vajrala9-Mar-09 3:12 
Questionusing windows workflow in a web based library circulation system and using visual studio 2005 Pinmembersohair zaki17-Jul-08 17:34 
AnswerRe: using windows workflow in a web based library circulation system and using visual studio 2005 Pinmemberindyfromoz24-Jul-08 1:29 
GeneralBiztalk Training Pinmemberparagme14-Jul-08 19:00 
Hi Prabhjyot,
 
I called you couple of months back for training in Biztalk Server, and you said you don't give training to experienced developers! Can you pls tell me why ?? I am interested in taking training for Biztalk 2006 R2.
 
More about me at http://iparag.com/about/ . Mail me at parag at iparag dot com
 
Best Regards,
Parag Mehta
iparag.com

GeneralReally Nice Article PinmemberXibiaN10-Jun-08 16:05 
GeneralNice one topic PinmemberMember 447580715-May-08 23:51 
Generalnice work Pinmembermaruti_64315-May-08 23:17 
GeneralRe: nice work Pinmemberparagme14-Jul-08 19:01 
GeneralNice stuff for a new bie PinmemberSupratim Sengupta15-May-08 22:05 
GeneralA really Good Information Pinmemberurvi_30118215-May-08 20:58 
GeneralScreen shots PinmemberB.Tanner10-May-08 8:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 10 May 2008
Article Copyright 2008 by Prabhjot Singh Bakshi
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid