Download presentation
Presentation is loading. Please wait.
1
1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect Microsoft Ltd http://blogs.msdn.com/ericnel
2
2 Windows Communication Foundation
3
3 Agenda Why another way to do A to B Basic Principles of WCF Creating a Service
4
4 Challenges How do I ensure reliable connectivity? How do I support rich authentication types? How do I ensure interoperability with other platforms? How do I make my distributed applications less fragile? How do I make them “service- oriented?” Which programming model should I use?
5
5 Where Are We Today? Remoting ASMX / WSE DCOM System.Messaging Enterprise Services Microsoft Sockets RMI JAX-RPC CORBA JMS EJB J2EE Sockets
6
6 Side-by-side co-existence with existing distributed technologies Seamless communication with applications built on existing technologies Smooth upgrade of existing code to WCF Investment Protection Leveraging Existing Microsoft Investments ASMX ASMX ASMXESWSE3
7
7 using System.Web.Services; public class AccountingOperation { public string AccountName; public long Amount; } public class Accounting { [WebMethod(TransactionOption=TransactionOption.RequiresNew)] public int AddEntry(AccountingOperation debit, AccountingOperation credit) { // Add entry to internal accounting book // return id. } } using System.ServiceModel; [ServiceContract(FormatMode=ContractFormatMode.XmlSerializer)] [OperationContract] [OperationBehavior(AutoEnlistTransaction=true)] // ASMX to WCF
8
8 Basic Principles Clients and Services Endpoints A, B, C Behaviors
9
9 Client Service Clients and Services
10
10 Client Service Endpoints Endpoint
11
11 Client Service Address, Binding, Contract CBA CBA CBA A BC Address Where? Contract What? Binding How?
12
12 Client Service Behaviors CBA CBA CBA A BC B B B
13
13 Selecting… AddressBinding BehaviorContract HTTP Transport TCPTransport NamedPipe Transport MSMQ Transport Custom Transport WS-Security Protocol WS-RM Protocol WS-Coord Protocol Duplex Channel Custom Protocol http://... net.tcp://... net.pipe://... net.msmq://... xxx://... ThrottlingBehavior Metadata Behavior Error Behavior Custom Behavior Instancing Behavior Concurrency Behavior Transaction Behavior Security Behavior Request/ Response One-Way Duplex net.p2p://... PeerTransport Externally visible, per-endpoint Opaque, per-service, endpoint, or operation
14
14 Creating a Service Define What to Expose (Contract) Implement Contract Define Endpoint(s) Define How to Expose (Binding) Define Where to Expose (Address) Host & Run Service
15
15 C ontracts A Service is a CLR Class that Implements One or More Service Contracts [DataContract] public class OrderDetail { [DataMember] public string ItemName { get; set; } [DataMember] public Guid ItemId { get; set; } [DataMember] public double ItemPrice { get; set; } } [ServiceContract] public interface IOrderProcessingService { [OperationContract(IsOneWay = true)] void ProcessOrder(OrderDetail detail); } class OrderProcessingService : IOrderProcessingService { public void ProcessOrder(OrderDetail detail) {... } } [DataContract] public class OrderDetail { [DataMember] public string ItemName { get; set; } [DataMember] public Guid ItemId { get; set; } [DataMember] public double ItemPrice { get; set; } } [ServiceContract] public interface IOrderProcessingService { [OperationContract(IsOneWay = true)] void ProcessOrder(OrderDetail detail); } class OrderProcessingService : IOrderProcessingService { public void ProcessOrder(OrderDetail detail) {... } }
16
16 Encoding Text, Binary, MTOM, Custom Transport Selection TCP, HTTP, Named Pipes, Peer Channel, MSMQ, Custom End-to-End Security Confidentiality, Integrity, AuthN, AuthZ, Federation & Infocard X.509, Username/Password, Kerberos, SAML, XrML, Custom End-to-End Reliable Messaging Transport-Independent QoS (In-Order / Exactly-Once) Volatile and Durable Queues for Availability Transactions Shared Transactions for “Synchronous” Operations Transactional Queues for “Asynchronous” Operations B inding
17
17 A ddresses http://microsoft.com:80/OrderService/WShttps://microsoft.com:443/OrderService/BPnet.tcp://microsoft.com:808/OrderService/TCPnet.pipe://microsoft.com/OrderService/NP Scheme http, https, net.tcp, net.pipe Host Name microsoft.com Port (Optional) * 80, 443, 808 Base Path /OrderService/ Endpoint Address WS, BP, TCP, NP * - Port Does Not Apply to Named Pipes
18
18 Hosting ServiceHost allows for hosting anywhere Console applications Windows applications Windows services IIS provides an enterprise class hosting environment Edit a.svc file and point at your service HTTP transport in IIS 6.0 All transports in IIS 7.0 (Windows Activation Service)
19
19 ServiceHost Allows a WCF Service to be Hosted in Any AppDomain EXE, NT Service, WinForms, Avalon, etc. public static void Main(string[] args) { ServiceHost host = new ServiceHost( typeof(OrderProcessingService); host.BaseAddresses.Add( new Uri(“http://localhost/OrderService/”)); host.Open(); } public static void Main(string[] args) { ServiceHost host = new ServiceHost( typeof(OrderProcessingService); host.BaseAddresses.Add( new Uri(“http://localhost/OrderService/”)); host.Open(); }
20
20 Windows Communication Foundation Svctraceviewer.exeSvcconfigeditor.exe + so much more
21
21 Windows Workflow Foundation
22
22 Agenda Introduction to Windows Workflow Foundation Workflow basics Activities basics
23
23 Windows Workflow Foundation Windows Workflow Foundation is the programming model, engine and tools for quickly building workflow enabled applications on Windows. Single workflow technology for Windows Available to all customers of Windows Available for use across a broad range of scenarios Redefining workflow Extensible framework & API to build workflow centric products One technology for human and system workflow Take workflow mainstream Incremental learning for mainstream.NET developer Fundamental part of Office 2007 Strong workflow partner & solution ecosystem
24
24.NET Framework 3.0 Workflow and BizTalk Server Windows Workflow Foundation Messaging DesignTools BusinessActivityMonitorAndAdminTools Orchestration Transformation Adapters BizTalk Server Accelerators Premium BPM server Premium BPM server Application to application and B2B integrationApplication to application and B2B integration Connects multiple services built with WCFConnects multiple services built with WCF Adapters to multiple products like SAP and MQSeriesAdapters to multiple products like SAP and MQSeries Business activity monitoringBusiness activity monitoring Vertical solutions and industry acceleratorsVertical solutions and industry accelerators Message transformation servicesMessage transformation services Enterprise single sign-onEnterprise single sign-on End-to-end health and activity trackingEnd-to-end health and activity tracking And more…And more… Workflow framework Workflow framework Exposed via.NET 3.0 Exposed via.NET 3.0 Broad set of scenarios Broad set of scenarios Used to build solutions Used to build solutions Enables manageability Enables manageability and scale-out in solutions Use for building workflow into apps or workflow-enabled servers Use for building workflow into apps or workflow-enabled servers Visual Studio Designer Workflow
25
25 What is a workflow? A set of activities that coordinate people and / or software... EscalateToManager Example activities…. CheckInventory Like a flowchart…. …organized into a workflow. Or a state diagram….
26
26 Why Workflow Technology? Long running and stateful behavior Transparency Flexible control flow Developer Productivity Workflows technology provides abstractions convenient to describe real world workflows Workflow Technology Value-Add
27
27 Why Workflow Technology? “Orders are confirmed in 48 hours and shipped within 30 days.” “Most suppliers confirm our orders but some forget and we need to followup.” “What are the next steps in handling this order?” Long Running and Stateful Workflows run for up to 30 days and maintain state throughout Flexible Control Flow Flexibility for people to override or skip steps in the workflow Transparency Rendering a visualization of next steps based on defined control flow Real World Examples Workflow Value-Add
28
28 Windows Workflow Foundation Key Concepts Host Process Windows Workflow Foundation Runtime Engine A Workflow An Activity Runtime Services Base Activity Library Custom Activity Library Visual Designer Visual Designer: Graphical and code- based construction Workflows are a set of Activities Workflows run within a Host Process: any application or server Developers can build their own Custom Activity Libraries Components Base Activity Library: Out-of-box activities and base for custom activities Runtime Engine: Workflow execution and state management Runtime Services: Hosting flexibility and communication
29
29 Workflow Basics A workflow is a class A workflow class may be defined in markup … using System.Workflow.Activities; public class Workflow1 : SequentialWorkflow { }
30
30 Workflow Basics Workflow constructor configures contained activities (like forms & controls) using System.Workflow.Activities; public partial class Workflow1 : SequentialWorkflow { public Workflow1() { InitializeComponent(); } public sealed partial class Workflow1 : SequentialWorkflow { private Delay delay1; private void InitializeComponent() { this.delay1 = new System.Workflow.Activities.Delay(); this.delay1.ID = “delay1"; this.delay1.TimeoutDuration = System.TimeSpan.Parse("00:00:05"); this.Activities.Add(this.delay1); this.ID = "Workflow1"; }
31
31 Workflow Authoring Modes.NET assembly ctor defines workflow Markup Only “Declarative” XAML Markup and Code C#/VB Code Only ApplicationGenerated XAML C#/VB XML defines XML defines workflow structure logic and data flow XML defines XML definesworkflow Code-beside Code-beside defines extra logic Code creates Code createsworkflow in constructor XAML C#/VB App creates activity tree and serializes Workflow Compiler wfc.exe C#/VB Compiler
32
32 Workflows
33
33 Activity Basics An activity is a step in a workflow Unit of execution, re-use and composition Think of Forms & Controls Activity == Controls Workflows == Forms Activities fall under two broad categories Basic – steps that “do work” Composite – manage a set of child activities Activities are classes Have properties and events that are programmable within your workflow code Have methods (e.g. Execute) that are only invoked by the workflow runtime
34
34 Example: A SendMail Activity using System.Workflow.ComponentModel; public partial class SendMail : System.Workflow.ComponentModel.Activity { public SendMail() { InitializeComponent(); } protected override Status Execute(ActivityExecutionContext context) { // my logic here to send the email return Status.Closed; } public partial class SendMail { public string subject; public string Subject { get { return subject; } set { this.subject = value; } } private void InitializeComponent() // designer generated { this.ID = "SendMail"; }
35
35 Activities: An Extensible Approach OOB activities, workflow types, base types base typesGeneral-purpose Activity libraries define workflow define workflow constructs constructs Create/Extend/ Compose activities App-specific building blocks First-class citizens Base Activity Library Custom Activity Libraries Author new activity Out-of-Box Activities Extend activity Compose activities Vertical-specific activities & workflows Best-practice IP & Knowledge Domain-Specific Workflow Packages Compliance RosettaNet CRM IT Mgmt
36
36 Combining WCF and WF
37
37 Coordinating Services Workflows are an excellent way to coordinate work across multiple services Service interaction is modeled using activities in a workflow Service interaction can be visualized Data can be flowed from one activity and service to another Workflows simplify asynchronous service calls and complex message exchange patterns Parallel execution, delays, time-outs, etc. Service interaction can easily be modified and dynamically changed Coordinating Services
38
38 Implementing Services using Workflow Challenges developing services today Services are often used together as part of a business process, but are not explicitly associated Services often front-end, long-running business processes Workflows are an excellent way to implement the logic behind services State management across multiple service interactions Services are associated together in a workflow model Implementation of services can be transparent Enables visibility into the state of the service Configurable runtime behavior Tracking, persistence, transactions, threading, etc. Workflows exposed through services
39
39 The Workflow/Service Ecosystem Solutions will often combine both approaches Workflow
40
40 Call To Action WCF is “no brainer” for future connectivity Use it Don’t necessarily need to port to it Use WF Build workflow into your applications Make you applications more flexible and configurable Build workflow enabled servers for other developers to target Build custom activity libraries for others to re-use Build solutions on top of workflow enabled products like Office 2007
41
41 Resources MSDN® http://msdn.microsoft.com/winfx/technologies/c ommunication/ http://msdn.microsoft.com/winfx/technologies/c ommunication/ http://msdn.microsoft.com/workflow Community Site http://www.netfx3.com/ Subscribe to the RSS feed for news & updates Find, download, & register Activities Find blogs, screencasts, whitepapers, and other resources Download samples, tools, and runtime service components
42
42 © 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
43
43 WCF Code Migration
44
44 using System.Web.Services; public class AccountingOperation { public string AccountName; public long Amount; } public class Accounting { [WebMethod(TransactionOption=TransactionOption.RequiresNew)] public int AddEntry(AccountingOperation debit, AccountingOperation credit) { // Add entry to internal accounting book // return id. } } using System.ServiceModel; [ServiceContract(FormatMode=ContractFormatMode.XmlSerializer)] [OperationContract] [OperationBehavior(AutoEnlistTransaction=true)] // ASMX to WCF
45
45 public class Accounting : ServicedComponent { public void AddCreditEntry(string creditAccount, int creditAmount) { } using System.EnterpriseServices; [ComponentAccessControl] [SecureMethod] [Transaction(TransactionOption.Required)] [SecurityRole("Manager")] using System.ServiceModel; [ServiceContract] [OperationContract] [OperationBehavior(AutoEnlistTransaction=true)] [PrincipalPermission(SecurityAction.Demand, Role="Managers")] // Enterprise Services to WCF
46
46 using Microsoft.Web.Services3; [WebService] class HelloWorld { [WebMethod] public string Hello (string text) { MessageSignature signature = (MessageSignature) RequestSoapContext.Current.Security.Elements[0]; if (!signature.SigningToken.Principal.IsInRole ("BUILTIN\Administrators")) throw new AuthorizationException("Access denied"); return String.Format("Hello, {0}", text); } } Note: Configuration entry changes are required [OperationContract] [PrincipalPermission(SecurityAction.Demand, null, "BUILTIN\Administrators")] using System.ServiceModel; [ServiceContract] // // // // // // // // WSE to WCF
47
47 class MyQService { public void ReceiveOrders() { MessageQueue Queue = new MessageQueue(@".\private$\Books"); XmlMessageFormatter formatter = new XmlMessageFormatter( new Type[] { typeof(System.Data.DataSet)}); Queue.Formatter = formatter; System.Messaging.Message msg = null; while((msg= Queue.Receive()) != null) { DataSet booklist = (DataSet) msg.Body; ProcessOrders(booklist); } } Public void ProcessOrder(DataSet BookList) {... } } using System.Messaging; using System.ServiceModel; [ServiceContract] [OperationContract(IsOneWay = true)] // // // // // // // // // // // // // System.Messaging to WCF
48
48 using System.Runtime.Remoting; [Serializable] public class AccountingOperation { public string AccountName; public long Amount; } public class Accounting { public int AddEntry(AccountingOperation debit, AccountingOperation credit) { // Add entry to internal accounting book // return id. } } using System.ServiceModel; [ServiceContract] [OperationContract] : MarshalByRefObject //.NET Remoting to WCF
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.