15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1328 ❘ ChaPTer 44 windOws wOrkflOw fOundAtiOn 4<br />

UploadPropertyInformation<br />

Return Guid<br />

While (!finished)<br />

Pick<br />

UploadRoomInformation<br />

DetailsComplete<br />

figure 44-14<br />

Defining the WorkflowserviceHost<br />

The workflow begins in a Receive activity which defines the initial service operation of<br />

UploadPropertyInformation. The data received from the service call is stored within the workflow <strong>and</strong> a<br />

Guid is then returned to the caller by the Send activity. This Guid uniquely defines this workflow instance<br />

<strong>and</strong> is used when calling back to that instance in the other operations.<br />

Once these initial two activities have completed, the workflow then runs a While activity within which<br />

there is a Pick activity with two branches. The first branch has a Receive activity with an operation<br />

named UploadRoomInformation <strong>and</strong> the second has a Receive activity with an operation named<br />

DetailsComplete.<br />

The code shown in the following snippet is used to host the workflow. It makes use of the<br />

WorkflowServiceHost class, which is very similar to the ServiceHost class available with WCF.<br />

string baseAddress = "http://localhost:8080/PropertyService";<br />

using (WorkflowServiceHost host =<br />

new WorkflowServiceHost(GetPropertyWorkflow(), new Uri(baseAddress)))<br />

{<br />

host.AddServiceEndpoint(XName.Get("IProperty", ns),<br />

new BasicHttpBinding(), baseAddress);<br />

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();<br />

smb.HttpGetEnabled = true;<br />

host.Description.Behaviors.Add(smb);<br />

try<br />

{<br />

host.Open();<br />

}<br />

Console.WriteLine("Service host is open for business...");<br />

Console.ReadLine();<br />

}<br />

finally<br />

{<br />

host.Close();<br />

}<br />

code download 07_WorkflowsAsServices<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!