ed pinto pm microsoft corporation. host “dublin”(iis/was + app server extensions) microsoft...
TRANSCRIPT
Building WCF Services with WF in .NET 4.0
Ed PintoPMMicrosoft 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
Host“Dublin”(IIS/WAS + App Server Extensions)
Microsoft ® .NET Workflow Service <your own>.exe
WF Runtime
What is WF?
WF programs coordinate work with minimal ceremony
Activities Runtime Tooling
Tooling
VS Designer VS Debugger Rehosted Designer
Workflow
Activity Library
Activities are the primitive abstraction for behaviorActivities are composable with other ActivitiesActivities have user-defined Variables for data storageActivities bind Arguments to in-scope VariablesActivities define Arguments to declare the type of data that can flow into or out of an ActivityFlow Chart
Parallel
Sequence
Activities
Send Message
Delay Receive Message
Generate Order
InArgument<TimeSpan>
OutArgument<Order>
InArgument<Message>
OutArgument<Message>
Process Order
Send Report
Variables
Variables
Variables
Instances
Management Endpoint
BehaviorsPersistence
Tracking
ServiceHostBase
…Tracking
Workflow Service Host
Activity Library
SendMessage
WCF and WF
ReceiveMessage
...
Instances
Management Endpoint
BehaviorsPersistence
Tracking
ServiceHostBase
…Tracking
Workflow Service Host
Activity Library
SendMessage
WCF and WF
ReceiveMessage
...
Coordinating Asynchronous Concurrency//Simple to author and maintain, performs poorly[OperationContract]public Picture GetPicture(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);}
Picture EndGetPicture(IAsyncResult result){ return PictureAsyncResult.End(result);}
Coordinating Asynchronous Concurrency//Simple to author and maintain, calls are sequential[OperationContract]public Picture GetPicture(string name){ //blocking I/O byte[] bytes = mediaService.GetMedia(name); //blocking I/O PictureInfo info = 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);}
Picture EndGetPicture(IAsyncResult result){ return BiggerPictureAsyncResult.End(result);}
Coordinating Asynchronous Concurrency
Workflow Runtime
Client Operation
I/OScheduler
Parallel
GetMedia GetPictureInfo
Sequence
GetMedia
Other Activities
Coordinating Asynchronous Work
GetMedia
Client
PictureService
MediaService
GetPictureInfo
GetPicture
PictureInfo
Service
Coordinating Asynchronous Concurrency
demo
Try Catch Finally
Exception Handling Logic
Process Message
Variables
Sequence
Flow In Transaction Scope
Variables
Receive Message
Coordinating Error Handling
Exceptions Transactions Compensation /
Cancellation
CompensableActivity
Compensation Logic
Body
Variables
Do X
Compensate X
Correlation
Submit TaskJobId = 123
Task Complete JobId = 123
3. Send
4. Receive
1. Start Job 123
6. Job 123 Complete
Application
Application State
2. Store Job 123
5. Lookup Job 123
JobId 789JobId 456
JobId 123
Correlation
Correlation QueryChannels
Context
SendMessage/ReceiveMessage+ CorrelationHandle
Instance Store
Content (poid=123)
Workflow
Correlation
Submit Task
Task Complete
2. Send
4. Receive
1. Start Job 123
6. Job 123 Complete
CorrelationHandle
Query Results
JobId=123
Query Results
JobId=123
Application State
JobId 789JobId 456
JobId 123
Correlation Query
JobId = 123
Correlation Query
JobId = 123
SendMessage
ReceiveMessage
3. Store workflow with query results
5. Lookup workflow using query results
PictureInfo
Service
Correlation
GetMedia
Client
PictureService
MediaService
GetPictureInfo
GetPicture
Picture
Context Based Correlation
Context Based Correlation
Content Based Correlation
Media
PictureInfo
Message Correlation
demo
[OperationContract]public void SubmitOrder(Order order){ // your code here}
Workflow Service Host
Hosting and Monitoring
Persistence
Tracking
IIS/WAS Site/Service Configuration
Tracking
IIS Manager • Management• Control• Enumeration• Tracking
Management Endpoint
Tracking
Instances
WCF + WF + "Dublin"
PowerShellManagement APIs
Hosting and Monitoring
demo
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 ConfigAnd 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 [email protected]
Evals & Recordings
Please fill
out your
evaluation for
this session at:
This session will be available as a recording at:
www.microsoftpdc.com
Please use the microphones provided
Q&A
© 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
Correlation QueryChannels
Cookies Context
SendMessage/ReceiveMessage+ CorrelationHandle
Instance Store
Body Content (poid=123)
InstancesInstances
Management Endpoint
Behaviors
Persistence
Tracking
IIS/WASSite/Service
Configuration
Service Host[OperationContract]public void SubmitOrder(Order order){ // your code here} …
Tools Trace Viewer
Test Client
Tracking
Designer Debugger
IIS Manager • Management• Control• Enumeration• Tracking
Management Endpoint
Metadata
Tracking
…
WCFWCF + WFWCF + WF + "Dublin"
Workflow Service HostActivity Library
SendMessage
ReceiveMessage
…
Channels (HTTP, TCP, NamedPipes, …)
Config Editor
PowerShellManagement APIs
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
…
Host
WF Runtime
What is WF?
WF programs coordinate work with minimal ceremony
Activities Runtime Tooling
ToolingVS
DesignerVS
DebuggerRehosted Designer
WorkflowActivity Library
Correlation
Application
Submit OrderPOId = 123
Update OrderPOId = 123
POId 789POId 456
POId 123
Application State
1. Receive
2. Store PO 123
3. Receive
4. Lookup PO 123
5. Store PO 123
Coordinating Asynchronous Work
Xaml GetMedia(Name)Client
PictureService
MediaService
PictureInfo
Service
PictureInfo GetPictureInfo(Name)
Picture GetPicture(Name)