230 likes | 410 Views
Building Workflow Services in .NET 3.5. CLAEYS Kurt, ORDINA. www.devitect.net. Agenda. Windows Communication Foundation Overview. Client. Service. A. B. C. A. B. C. C. B. A. A. B. C. Address Where?. Binding How?. Contract What?. WCF Contracts. [ ServiceContract ]
E N D
Building Workflow Services in .NET 3.5 CLAEYS Kurt, ORDINA • www.devitect.net
Windows Communication Foundation Overview Client Service A B C A B C C B A A B C Address Where? Binding How? Contract What?
WCF Contracts [ServiceContract] public interface IKBO { [OperationContract] void RegisterCompany(CompanyFile data); } [DataContract] public class CompanyFile { [DataMember] public string companyName { get; set; } [DataMember] public string VATID { get; set; } }
Windows Workflow Foundation Overview Workflow Activities Activity Library Workflow Runtime Persistence Service
WorkflowServiceHost - Workflow ServiceHost Client WCF WCF WCF Endpoint WorkflowServiceHost Service WCF Endpoint Workflow A A B B C C
Start – More Input – Action ! WorfklowService Start Client 1 Client 2 Service Wait More Input Action
ReceiveActivity • Activity that implements an operation defined by a Windows Communication Foundation (WCF) service contract. • To implement service behavior : add child activities to the ReceiveActivity Client
Binding an operation contract to a ReceiveActivity • ServiceOperationInfo property • Add Contract = Workflow First • Import = Contract First
Contract First vs Workflow First approach • Contract First • You have a WCF contract (=interface) • You map receiveActivities in workflows to the operations in the contract • SOA • Workflow First Approach • No WCF contract present • Create contract as you model the workflow • More agile
ContextExhange Protocol some data Start “creates” instance Client 1 Client 2 some data + instanceID WorkflowPersistenceDB EC969B-4239-427E-BB0A-9F7E5610A1F0 instanceID some data + instanceID More Input “follows” instance EC969B-4239-427E-BB0A-9F7E5610A1F0
CanCreateInstance • CanCreateInstance (true/false) • Gets or sets whether the operation on a ReceiveActivity causes a new workflow service instance to be created or to participate in an already instantiated workflow.
Persisting the instance Start CanCreateInstance = true • Creates an InstanceID-Sends it to the Client • Allows to persists WF instance EC969B-4239-427E-BB0A-9F7E5610A1F0 CanCreateInstance = false More Input • Expects an InstanceID • Load persisted WF instance
SendActivity • Activity that models the synchronous invocation of a service operation. • Use ChannelToken as reference to client endpoint Service
ChannelToken - Endpoint <client> <endpoint address="http://localhost:4321/Foo" binding="basicHttpBinding" bindingConfiguration="" contract=“IFOO" name=“TheEndpointForTheService" /> </client>
WorkflowServiceHost WorkflowServiceHost host; host = new WorkflowServiceHost(typeof(TheWorkflow)); host.Open();
Participating Client DossierInterface.IDossier proxy; System.ServiceModel.Channels.Binding b; b = new NetTcpContextBinding(); EndpointAddress ea; ea = new EndpointAddress("net.tcp://localhost:9876/TheWorkflow"); proxy = ChannelFactory<DossierInterface.IDossier>. CreateChannel(b, ea); System.ServiceModel.Channels.IContextManager cm; cm = ((System.ServiceModel.IContextChannel)proxy). GetProperty<System.ServiceModel.Channels.IContextManager>(); var d = cm.GetContext(); d["instanceId"] = textBox1.Text; cm.SetContext(d); proxy.PaymentReceived();
Demo Scenario Step 1 User starts the process by filling in data in a webapplication Step 2 Process StartedGenerate paymentreference Step 3 User gets paymentreference Step 4 Process waits for payment for amount of time Step 5 User pays Step 6 Process receives payments and continues Step 7 Process data is send to external service
Wrap-up • What to remember about workflow services • Workflows Services is an easy technology to build processes that integrate WCF Services • Start with creating interfaces (= contract first approach) • Share interface to all participants • Importance of the instanceId • Database for persisting workflows makes the process long running ! • Have a delay activity for every ‘waiting for input’ scenario • Have a look at WCF 4.0 and Dublin !
Links • Some links to get you started ... • This Example • http://www.devitect.net/techdays09 • Workflow Services (Foundation) • http://msdn.microsoft.com/en-us/magazine/cc164251.aspx • Context Exhange Protocol • http://msdn.microsoft.com/en-us/library/bb924468.aspx • WF and WCF integration in .NET 3.5 • http://channel9.msdn.com/shows/The+EndPoint/WF-and-WCF-integration-in-NET-35/ • Workflow Services Samples (WF) • http://msdn.microsoft.com/nl-be/library/bb943473(en-us).aspx • Workflows, Services, and Models, A First Look at WF 4.0, “Dublin”, and “Oslo” • http://msdn.microsoft.com/en-us/library/dd200919.aspx
Thanks kurt.claeys@ordina.be