Docstoc

WFServices

Document Sample
WFServices Powered By Docstoc
					Name
Title
Microsoft Corporation
http://blog.address
Problem space
Architecture of WF Services
Context Exchange
Duplex
Conversations
What is Workflow?

 Workflow is the organization
 of work representing
 business process or
 application logic
What’s the value of Workflow?


  Long Running Logic
 Flexibility
 Transparency
                                               Address +
<service>
     <endpoint name=“MyService”                Binding +
             address=“MyAddress”
                                               Contract =
                binding=“netTcpBinding”
             contract=“IMyInterface” />        Endpoint

[ServiceContract]
public interface IMyInterface
                                               Service
{                                              Contract
    [FaultContract(typeof(MyFault)]
    [OperationContract]                        Definition
    public void MyMethod(MyDataContract);
}

[DataContract]                                 Data
public class MyDataContract
{    [DataMember]                              Contract
     public string MyField;                    Definition
}


[ServiceBehavior(InstanceContextMode=Single]
public class MyService: IMyInterface
                                               Service Type
{
     public void MyMethod(MyDataContract){…}
}
Advantages
  Service implemented as Workflow
     Leverage Workflow development experience
     Enforces application protocol by default
     Allows long-running, durable Services
  Workflow hosted as Service
     ServiceContract provides typed interface for integrating
     with the Workflow
     Messages enforce by-value, serializable data
     Workflows can be message-activated
Architecture
Service.cs
Workflow.cs or
Workflow.xoml
                               Service Runtime          Service Instance
                                                        Workflow Instance

                                    OperationInvoker
                            WorkflowOperationInvoker          Operation 1
                                                            ReceiveActivity 1
 App.config
                                    OperationSelector         Operation 2
                                                            ReceiveActivity 2
       Workflow
      ServiceHost
      ServiceHost                    InstanceProvider
                            DurableInstanceProvider
                                                        Workflow Runtime
                                   MessageInspector
                            MessageContextInspector



  ServiceDescriptio
                               ContextChannel
         n                                              WF Persistence DB
         ServiceBehavior
WorkflowServiceBehavior        ListenerChannel

        OperationBehavior
WorkflowOperationBehavior
Access control

  Authentication provided by WCF
  infrastructure
  Static access control is supported using
  WCF AuthorizationManager extensiblity
  ReceiveActivity
      PrincipalPermission (static, role based)
      OperationValidator (dynamic, claims based)
demo
Architecture

Service.cs
                                Service Runtime           Service Instance

                                      OperationInvoker          Operation 1
App.config
                                     OperationSelector          Operation 2
     ServiceHost
                                      InstanceProvider
                             DurableInstanceProvider
                                                         Persistence Provider
                                    MessageInspector
                             MessageContextInspector



    ServiceDescription
                                ContextChannel
          ServiceBehavior
 DurableServiceBehavior         ListenerChannel

         OperationBehavior
 DurableOperationBehavior
demo
Transport model for exchange will not work
in long-running process
Manage at application or process layer
Need to agree upon a protocol to exchange
context so communication can continue
         op x params


Send                     Receive
                                              Context repository (your choice)
          {instanceId}
         op x response


         op y params               op y params
          {instanceId}              {instanceId}          Other
Send                     Receive                         Service
                                                        Consumer
         op y response             op y response




Client                   Service
                            ContextChannel implements the
   Service Runtime          exchange of context token
        OperationInvoker
                            Receive
WorkflowOperationInvoker
                              Extract context to ContextMessageProperty
        OperationSelector     Apply context on response to activating (first)
                              request
         InstanceProvider
DurableInstanceProvider     Send
                              Add context to all outgoing messages
       MessageInspector
MessageContextInspector
                            Representation of context
                              SOAP header <wsc:Context />
                              HTTP cookie
   ContextChannel             In code:
   ListenerChannel            IDictionary<XmlQualifiedName, string>
// inside wf code application
IDictionary<XmlQualifiedName, string> context;
// context = … obtain context from store

sendActivity.Context = context;

//also, to dynamically set send address
sendActivity.CustomAddress =
    “net.tcp://140.141.2.5/service.svc”;
// my wpf application
IDictionary<XmlQualifiedName, string> context;
// context = … obtain context from store

IContextManager cm =
   proxy.InnerChannel.GetProperty<IContextManager>();

if (null != cm)
   cm.SetContext(context);


// need to use a channel stack which includes the
// context channel, or write the headers directly into
// the message (non-WCF) client
demo
NetTcpContextBinding
WSHttpContextBinding
BasicHttpContextBinding

<Your Binding Here>
  Create a custom binding and insert the
  ContextChannel into the Channel Stack
<customBinding>
  <binding   name="namedPipeWithContext">
    <context />
    <binaryMessageEncoding />
    <namedPipeTransport />
  </binding>
</customBinding>
Cannot rely on a duplex channel
Model this via two contracts (inside two
WorkflowServiceHost’s)
Explicitly provide “client” context in the
initiating message to the “server”
               “Client”                      “Service”
Duplex
Message
Flow                       BeginWorkflow
                                               Receive
                Send         {no context}      Request
               Request         ClientId

                             {ServiceId}
               Receive         Body
               Respose
 Use this to
                           BeginWorkItem
  route a
                 Send                          Receive
 message                     {ServiceId}
                               Body
   back
                          ContinueWorkItem     Receive
                 Send
                             {ServiceId}
                               Body
                          CompleteWorkItem     Receive
                 Send
                             {ServiceId}
                                 Body
                          WorkItemComplete      Send
               Receive
                              {ClientId}
                                Body
demo
Motivation: Overcome the blocking
  behavior of the send activity, allow
  workflow to continue while processing
  occurs.
Applicability: Interacting with a
  service which returns quickly while
  continuing work, notifies when
  complete
Implementation: See following
  demo
demo
Motivation: Allow control
  and time constraint of long
  running work. If a blocking
  call, enforce time at the
  channel stack.
Applicability: Interacting
  with a service which offers
  control operations for work
Structure: “Worker” service
  with callback and control
  operations
Implementation:
  ListenActivity with
  Completed, Cancelled and
  TimedOut branches
Multiple parties on the same contract
Need context to include more than WF ID
ReceiveActivity can be given a unique
context relative to the scope of conversation
These unique contexts must be provided
explicitly to all parties in the conversation
                                                                                {no context}
                                                                            InstanceId + ConvId1



                                                                                                        Shipper 1

                                Receive
                                 Order
                                                                                 {no context}
                                                                            InstanceId + ConvId2

                                                                                 {no context}
              Request            Request            Request
               Quote              Quote              Quote                  InstanceId + ConvId3
         Context1             Context2            Context3
                                                                                                        Shipper 2
              Receive            Receive            Receive
               Quote              Quote              Quote




                        Receive 2            Receive 3                                                  Shipper 3
Receive 1                                    Operation +
Operation +             Operation +
                        ConvId2              ConvId3
ConvId1
                                                                               {InstanceId + ConvId3}

                                                   {InstanceId + ConvId2}               Body
                    {InstanceId + ConvId1}                   Body
                             Body
demo
WF and WCF developers benefit from these
two worlds coming together
Workflow Services provide a natural way to
model services
With an understanding of context, advanced
communication patterns can be
implemented across many parties.
© 2007 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.