5,316,870 members and growing! (15,772 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Windows Workflow Foundation » General     Intermediate License: The Code Project Open License (CPOL)

Exposing Windows WorkFlow as Web services

By Trainer Prabhjot Bakhsi

to expose the Windows workflows as Web Service
C# (C# 1.0, C# 2.0, C# 3.0, C#), .NET (.NET, .NET 3.5, .NET 3.0)

Posted: 9 May 2008
Updated: 9 May 2008
Views: 2,875
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
47 votes for this Article.
Popularity: 6.57 Rating: 3.93 out of 5
7 votes, 14.9%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 4.3%
4
38 votes, 80.9%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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

Trainer Prabhjot Bakhsi


based out of Ahd and Pune, I am Corporate and Microsoft Certified Trainer on .net3.5 and Biztalk Server 2006 R2.

My client list- IBM(Hyd, Kol,Blr,Pune), Cap Gemini(Kol, Mum,Blr), Intel(Blr), Mcafee(Blr), KPIT(pune), Wipro(Hyd, Blr,Kol),Royal bank of Scotland(Gurgaon), SMTC(Dubai),Patni(Mumbai),CSI(Ahm), IEEE(Ahm), Pure(singapore) Delta(hyd),Ness(mum),Mphasis(Mum),Kanbay(hyd), Polaris(Gur), ICICI techProcess(mumbai), 3i Infotech(mum), HCL(Che),SunGard(Pune), For Microsoft (at Aces Goa and Virtusa Hyd),Solid Solution exact pvt. Ltd(Holland based).
Occupation: CEO
Company: BSP IT & Communication
Location: India India

Other popular Windows Workflow Foundation articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
Subject  Author Date 
Questionusing windows workflow in a web based library circulation system and using visual studio 2005membersohair zaki18:34 17 Jul '08  
GeneralBiztalk Trainingmemberparagme20:00 14 Jul '08  
GeneralReally Nice ArticlememberXibiaN17:05 10 Jun '08  
GeneralNice one topicmemberMember 44758070:51 16 May '08  
Generalnice workmembermaruti_6430:17 16 May '08  
GeneralRe: nice workmemberparagme20:01 14 Jul '08  
GeneralNice stuff for a new biememberSupratim Sengupta23:05 15 May '08  
GeneralA really Good Informationmemberurvi_30118221:58 15 May '08  
GeneralScreen shotsmemberB.Tanner9:44 10 May '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 9 May 2008
Editor:
Copyright 2008 by Trainer Prabhjot Bakhsi
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project