340 likes | 547 Views
Building WCF Services with WF in .NET 4.0. Ed Pinto PM Microsoft Corporation. Agenda. Motivation WF 4.0 Basics WCF and WF Async I/O Error Handling Correlation Hosting and Monitoring Other WCF 4.0 Improvements. Challenges. Work is increasingly distributed
E N D
Building WCF Services with WF in .NET 4.0 Ed Pinto PM Microsoft Corporation
Agenda • Motivation • WF 4.0 Basics • WCF and WF • Async I/O • Error Handling • Correlation • Hosting and Monitoring • Other WCF 4.0 Improvements
Challenges • Work is increasingly distributed • Coordination code creates complexity • Coordinating messages with application state • Coordinating calls to a database or another service (Async I/O) • Coordinating rainy day scenarios • Management and tracking of distributed work is difficult
What is WF? Host“Dublin”(IIS/WAS + App Server Extensions)Microsoft ® .NET Workflow Service <your own>.exe Workflow • WF programs coordinate work with minimal ceremony • Activities • Runtime • Tooling Activity Library WF Runtime Tooling VS Designer VS Debugger Rehosted Designer
Activities Activities are the primitive abstraction for behavior Activities are composable with other Activities Activities have user-defined Variables for data storage Activities bind Argumentsto in-scope Variables Activities define Arguments to declare the type of data that can flow into or out of an Activity Flow Chart Variables Sequence OutArgument<Order> Variables Parallel InArgument<TimeSpan> OutArgument<Message> Variables Generate Order Delay Receive Message InArgument<Message> Process Order Send Message Send Report
WCF and WF Workflow Service Host Activity Library Management Endpoint SendMessage Instances Behaviors Persistence ReceiveMessage Tracking Tracking ... … ServiceHostBase
WCF and WF Workflow Service Host Activity Library Management Endpoint SendMessage Instances Behaviors Persistence ReceiveMessage Tracking Tracking ... … ServiceHostBase
Coordinating Asynchronous Concurrency //Simple to author and maintain, performs poorly [OperationContract] public PictureGetPicture(string name) { //blocking I/O byte[] bytes = mediaService.GetMedia(name); return new Picture{ Bytes = bytes, Name = name}; } //Performs well, difficult to author and maintain [OperationContract(AsyncPattern = true)] IAsyncResult public BeginGetPicture(string name, AsyncCallback callback, object state) { return new PictureAsyncResult(name, callback, state); } PictureEndGetPicture(IAsyncResult result) { returnPictureAsyncResult.End(result); }
Coordinating Asynchronous Concurrency //Simple to author and maintain, calls are sequential [OperationContract] public PictureGetPicture(string name) { //blocking I/O byte[] bytes = mediaService.GetMedia(name); //blocking I/O PictureInfoinfo = pictuerInfoService.GetPictureInfo(name); return new Picture{ Bytes = bytes, PictureInfo = info }; } //calls can be made in parallel, difficult to author and maintain [OperationContract(AsyncPattern = true)] IAsyncResult public BeginGetPicture(string name, AsyncCallback callback, object state) { return new BiggerPictureAsyncResult(name, callback, state); } PictureEndGetPicture(IAsyncResult result) { returnBiggerPictureAsyncResult.End(result); }
Coordinating Asynchronous Concurrency Sequence Parallel GetMedia GetMedia GetPictureInfo Other Activities Workflow Runtime Client Operation I/O Scheduler
Coordinating Asynchronous Work PictureService Client GetPicture PictureInfoService GetPictureInfo MediaService GetMedia
demo Coordinating Asynchronous Concurrency
Exceptions Transactions Compensation / Cancellation Coordinating Error Handling Try Catch Finally Sequence Variables Variables Process Message Flow In Transaction Scope Do X CompensableActivity Variables Receive Message Body Exception Handling Logic Compensate X Compensation Logic
Correlation 1. Start Job 123 Application 2. Store Job 123 3. Send Submit TaskJobId = 123 JobId 789 JobId 456 JobId 123 4. Receive 5. Lookup Job 123 Task Complete JobId = 123 6. Job 123 Complete Application State
Correlation SendMessage/ReceiveMessage+ CorrelationHandle Instance Store Channels Correlation Query Context Content (poid=123)
Correlation 1. Start Job 123 Workflow CorrelationHandle 2. Send 3. Store workflow with query results SendMessage Submit Task JobId 789 JobId 456 JobId 123 4. Receive 5. Lookup workflow using query results ReceiveMessage Task Complete Application State JobId = 123 JobId = 123 Correlation Query Correlation Query JobId=123 JobId=123 Query Results Query Results 6. Job 123 Complete
Correlation PictureService Client GetPicture PictureInfoService GetPictureInfo Picture PictureInfo Context Based Correlation Context Based Correlation Content Based Correlation GetMedia MediaService Media
demo Message Correlation
Hosting and Monitoring WCF + WF + "Dublin" • IIS Manager • Management • Control • Enumeration • Tracking Workflow Service Host Management Endpoint PowerShellManagement APIs Instances [OperationContract] public void SubmitOrder(Order order){ // your code here } Persistence Tracking Tracking Tracking Site/Service Configuration IIS/WAS
demo Hosting and Monitoring
When Should I Write WCF Services using Workflow? • Consider Workflow Services if your service: • Calls a database, calls another service, or uses the file system • Coordinates parallel work • Enforces ordering between messages • Coordinates messages with application state • Is long running • Requires rich tracking information
Other WCF 4.0 Improvements • REST toolkit • Discovery • Local Services • New Channels: UDP, Http Polling Duplex • Standards: SOAP over UDP, BP 1.2 • Standard Endpoints • Durable Duplex • Simplified Config And much much more….
Conclusion • WF and WCF push complex coordination to the framework • Async I/O • Error Handling • Correlation • WF and WCF make service state queryable • “Dublin” provides enterprise • Persistence • Tracking • Management • More …
Resources • Breakout Sessions • BB18 - "Dublin": Hosting and Managing Workflows and Services • TL38 - WCF: Zen of Performance and Scale • TL35 - WCF: Developing RESTful Services • TL17 - WF 4.0: A First Look • TL21 - WF 4.0: Extending with Custom Activities • TL36 - Microsoft .NET Framework: Declarative Programming Using XAML • BB27 - .NET Services: Orchestrating Services and Business Processes Using Cloud-Based Workflow • http://msdn.microsoft.com/wcf/future/ • http://msdn.microsoft.com/wf/future/ • Questions to wfpdc@microsoft.com
Evals & Recordings Please fill out your evaluation for this session at: This session will be available as a recording at: www.microsoftpdc.com
Q&A Please use the microphones provided
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Correlation SendMessage/ReceiveMessage+ CorrelationHandle Instance Store Channels Correlation Query Cookies Context Body Content (poid=123)
WCF + WF WCF WCF + WF + "Dublin" Tools Trace Viewer Test Client Config Editor Designer Debugger Workflow Service Host • IIS Manager • Management • Control • Enumeration • Tracking Activity Library Management Endpoint Management Endpoint SendMessage ReceiveMessage … PowerShellManagement APIs Behaviors Service Host Metadata Instances Instances [OperationContract] public void SubmitOrder(Order order) { // your code here } Persistence … Tracking Tracking Tracking … Channels (HTTP, TCP, NamedPipes, …) Site/Service Configuration IIS/WAS
WCF 4.0 Improvements • Rest toolkit • Standards: • SOAP over UDP, WS-Discovery, WS-BA, WS-RSP, BP 1.2 • Local Services • New Channels • UDP, Polling Http Duplex • Discoverable services • Programming model simplifications • Standard Endpoints • Config • …
What is WF? Host • WF programs coordinate work with minimal ceremony • Activities • Runtime • Tooling Workflow Activity Library WF Runtime Tooling VS Designer VS Debugger Rehosted Designer
Correlation 1. Receive Application 2. Store PO 123 Submit OrderPOId = 123 POId 789 POId 456 3. Receive POId 123 4. Lookup PO 123 Update OrderPOId = 123 5. Store PO 123 Application State
Coordinating Asynchronous Work PictureService Client Picture GetPicture(Name) MediaService XamlGetMedia(Name) PictureInfoService PictureInfoGetPictureInfo(Name)