1 understanding windows communication foundation and workflow foundation eric nelson...

48
1 Understanding Windows Understanding Windows Communication Foundation Communication Foundation and and Workflow Foundation Workflow Foundation Eric Nelson Eric Nelson [email protected] Application Architect Application Architect Microsoft Ltd Microsoft Ltd http:// blogs.msdn.com/ericnel

Post on 22-Dec-2015

224 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

1

Understanding Windows Understanding Windows Communication Foundation Communication Foundation and and Workflow FoundationWorkflow Foundation

Eric Nelson Eric Nelson [email protected] Application ArchitectApplication ArchitectMicrosoft LtdMicrosoft Ltdhttp://blogs.msdn.com/ericnel

Page 2: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

2

Windows Windows Communication Communication FoundationFoundation

Page 3: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

3

AgendaAgenda

Why another way to do A to BWhy another way to do A to B

Basic Principles of WCFBasic Principles of WCF

Creating a Service Creating a Service

Page 4: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

4

ChallengesChallengesHow 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?

Page 5: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

5

Where Are We Today?Where Are We Today?

Remoting

ASMX / WSE

DCOM

System.Messaging

Enterprise Services

Microsoft

Sockets

RMI

JAX-RPC

CORBA

JMS

EJB

J2EE

Sockets

Page 6: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

6

Side-by-side co-Side-by-side co-existence with existing existence with existing distributed technologiesdistributed technologies

Seamless Seamless communication with communication with applications built on applications built on existing technologiesexisting technologies

Smooth upgrade of Smooth upgrade of existing code to WCFexisting code to WCF

Investment ProtectionInvestment ProtectionLeveraging Existing Microsoft Leveraging Existing Microsoft InvestmentsInvestments

ASMXASMX

ASMXASMX

ASMXASMX ESES WSE3WSE3

Page 7: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

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 WCFASMX to WCF

Page 8: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

8

Basic PrinciplesBasic Principles

1.1. Clients and Services Clients and Services

2.2. Endpoints Endpoints

3.3. A, B, C A, B, C

4.4. BehaviorsBehaviors

Page 9: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

9

Client Service

Clients and ServicesClients and Services

Page 10: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

10

Client Service

EndpointsEndpoints

EndpointEndpoint

Endpoint

Endpoint

Page 11: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

11

Client Service

Address, Binding, ContractAddress, Binding, Contract

CBA

CBA

CBA

ABC

AddressWhere?

ContractWhat?

BindingHow?

Page 12: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

12

Client Service

BehaviorsBehaviors

CBA

CBA

CBA

ABC

B BB

Page 13: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

13

Selecting…Selecting…Address Binding BehaviorContract

HTTPHTTPTransportTransport

TCPTCPTransportTransport

NamedPipeNamedPipeTransportTransport

MSMQMSMQTransportTransport

CustomCustomTransportTransport

WS-SecurityWS-SecurityProtocolProtocol

WS-RMWS-RMProtocolProtocol

WS-CoordWS-CoordProtocolProtocol

DuplexDuplexChannelChannel

CustomCustomProtocolProtocol

http://...http://...

net.tcp://...net.tcp://...

net.pipe://...net.pipe://...

net.msmq://...net.msmq://...

xxx://...xxx://...

ThrottlingThrottlingBehaviorBehavior

MetadataMetadataBehaviorBehavior

Error Error BehaviorBehavior

CustomCustomBehaviorBehavior

InstancingInstancingBehaviorBehavior

ConcurrencyConcurrencyBehaviorBehavior

TransactionTransactionBehaviorBehavior

SecuritySecurityBehaviorBehavior

Request/Request/ResponseResponse

One-WayOne-Way

DuplexDuplex

net.p2p://...net.p2p://...PeerPeer

TransportTransport

Externally visible,

per-endpoint

Opaque, per-service,endpoint, or operation

Page 14: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

14

Creating a ServiceCreating a Service

1.1. Define Define WhatWhat to Expose (Contract) to Expose (Contract)

2.2. Implement Contract Implement Contract

3.3. Define Endpoint(s)Define Endpoint(s)1.1. Define Define How How to Expose (Binding)to Expose (Binding)

2.2. Define Define WhereWhere to Expose (Address) to Expose (Address)

4.4. Host & Run Service Host & Run Service

Page 15: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

15

CContractsontractsA Service is a CLR Class that A Service is a CLR Class that Implements One or More Service Implements One or More Service ContractsContracts[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) { ... }}

Page 16: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

16

EncodingEncodingText, Binary, MTOM, CustomText, Binary, MTOM, Custom

Transport SelectionTransport SelectionTCP, HTTP, Named Pipes, Peer Channel, MSMQ, CustomTCP, HTTP, Named Pipes, Peer Channel, MSMQ, Custom

End-to-End SecurityEnd-to-End SecurityConfidentiality, Integrity, AuthN, AuthZ, Federation & InfocardConfidentiality, Integrity, AuthN, AuthZ, Federation & InfocardX.509, Username/Password, Kerberos, SAML, XrML, CustomX.509, Username/Password, Kerberos, SAML, XrML, Custom

End-to-End Reliable MessagingEnd-to-End Reliable MessagingTransport-Independent QoS (In-Order / Exactly-Once)Transport-Independent QoS (In-Order / Exactly-Once)

Volatile and Durable Queues for AvailabilityVolatile and Durable Queues for Availability

TransactionsTransactionsShared Transactions for “Synchronous” OperationsShared Transactions for “Synchronous” Operations

Transactional Queues for “Asynchronous” OperationsTransactional Queues for “Asynchronous” Operations

BBindinginding

Page 17: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

17

AAddressesddresseshttp://microsoft.com:80/OrderService/WShttp://microsoft.com:80/OrderService/WS

https://microsoft.com:443/OrderService/BPhttps://microsoft.com:443/OrderService/BP

net.tcp://microsoft.com:808/OrderService/TCPnet.tcp://microsoft.com:808/OrderService/TCP

net.pipe://microsoft.com/OrderService/NPnet.pipe://microsoft.com/OrderService/NP

SchemeScheme http, https, net.tcp, http, https, net.tcp, net.pipenet.pipe

Host NameHost Name microsoft.commicrosoft.comPort (Optional) Port (Optional) **

80, 443, 80880, 443, 808

Base PathBase Path /OrderService//OrderService/Endpoint Endpoint AddressAddress

WS, BP, TCP, NPWS, BP, TCP, NP* - Port Does Not Apply to Named Pipes* - Port Does Not Apply to Named Pipes

Page 18: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

18

HostingHosting

ServiceHostServiceHost allows for hosting allows for hosting anywhereanywhere

Console applicationsConsole applications

Windows applicationsWindows applications

Windows servicesWindows services

IIS provides an enterprise class IIS provides an enterprise class hosting environmenthosting environment

Edit a Edit a .svc.svc file and point at your service file and point at your service

HTTP transport in IIS 6.0HTTP transport in IIS 6.0

All transports in IIS 7.0 (Windows All transports in IIS 7.0 (Windows Activation Service)Activation Service)

Page 19: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

19

ServiceHostServiceHost

Allows a WCF Service to be Hosted in Allows a WCF Service to be Hosted in Any AppDomainAny AppDomain

EXE, NT Service, WinForms, Avalon, etc.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();}

Page 20: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

20

Windows Windows Communication Communication FoundationFoundation

Svctraceviewer.exeSvctraceviewer.exe

Svcconfigeditor.exeSvcconfigeditor.exe

+ so much more+ so much more

Page 21: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

21

Windows Workflow Windows Workflow FoundationFoundation

Page 22: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

22

AgendaAgenda

Introduction to Windows Workflow Introduction to Windows Workflow FoundationFoundation

Workflow basics Workflow basics

Activities basicsActivities basics

Page 23: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

23

Windows Workflow Windows Workflow FoundationFoundationWindows Workflow Foundation is the programming Windows Workflow Foundation is the programming

model, engine and tools for quickly building model, engine and tools for quickly building workflow enabled applications on Windows.workflow enabled applications on Windows.

Single workflow technology for WindowsSingle workflow technology for WindowsAvailable to all customers of WindowsAvailable to all customers of WindowsAvailable for use across a broad range of scenariosAvailable for use across a broad range of scenarios

Redefining workflowRedefining workflowExtensible framework & API to build workflow centric Extensible framework & API to build workflow centric productsproductsOne technology for human and system workflowOne technology for human and system workflow

Take workflow mainstreamTake workflow mainstreamIncremental learning for mainstream .NET Incremental learning for mainstream .NET developerdeveloperFundamental part of Office 2007Fundamental part of Office 2007Strong workflow partner & solution ecosystemStrong workflow partner & solution ecosystem

Page 24: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

24

.NET Framework 3.0.NET Framework 3.0

Workflow and BizTalk Workflow and BizTalk ServerServer

Windows Windows Workflow Workflow

FoundationFoundation

MessagingMessagingDesigDesig

nnToolsTools

BusinesBusinesss

ActivityActivityMonitorMonitor

AndAndAdminAdminToolsTools

OrchestratioOrchestrationn

TransformatiTransformationon

AdaptersAdapters

BizTalk ServerAcceleratorsAccelerators

• Premium BPM serverPremium 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 Adapters to multiple products like SAP and MQSeriesMQSeries•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 frameworkWorkflow framework• Exposed via .NET 3.0 Exposed via .NET 3.0 • Broad set of scenarios Broad set of scenarios • Used to build solutionsUsed to build solutions• Enables manageabilityEnables manageabilityand scale-out in solutionsand scale-out in solutions• Use for building workflow Use for building workflow into apps or workflow-enabled into apps or workflow-enabled serversservers

Visual Studio DesignerVisual Studio Designer

WorkflowWorkflow

Page 25: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

25

What is a workflow?What is a workflow?A set of A set of activitiesactivities that coordinate that coordinate

peoplepeopleand / or software...and / or software...

EscalateToManagerExample activities…. Example activities…. CheckInventory

Like a flowchart…. Like a flowchart….

……organized into a organized into a workflowworkflow..

Or a state diagram…. Or a state diagram….

Page 26: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

26

Why Workflow Why Workflow Technology?Technology?

Long running and stateful behaviorLong running and stateful behavior

TransparencyTransparency

Flexible control flowFlexible control flow

Developer ProductivityDeveloper Productivity

Workflows technology provides abstractionsWorkflows technology provides abstractions

convenient to describe real world workflowsconvenient to describe real world workflows

Workflow Technology Value-AddWorkflow Technology Value-Add

Page 27: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

27

Why Workflow Technology?Why Workflow Technology?

““Orders are Orders are confirmed in confirmed in

48 hours and shipped 48 hours and shipped within 30 days.”within 30 days.”““Most suppliersMost suppliers

confirm our orders confirm our orders but some forget and but some forget and

we need to followup.”we need to followup.”

““What are the next What are the next steps in handling this steps in handling this

order?”order?”

Long Running and Long Running and StatefulStateful

Workflows Workflows runrun for up to for up to 30 days and maintain 30 days and maintain

state throughoutstate throughoutFlexible Control Flexible Control

FlowFlowFlexibility for people Flexibility for people to override or skip to override or skip

steps in the workflowsteps in the workflowTransparencyTransparency

Rendering a Rendering a visualization of next visualization of next

steps based on defined steps based on defined control flowcontrol flow

Real World Examples Real World Examples Workflow Value-AddWorkflow Value-Add

Page 28: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

28

Windows Workflow FoundationWindows Workflow FoundationKey ConceptsKey Concepts

Host Process

WindowsWorkflow Foundation

Runtime Engine

A Workflow

An Activity

Runtime Services

Base Activity Library

Custom Activity Library

Visual Designer

Visual Designer:Visual Designer: Graphical and Graphical and code-based constructioncode-based construction

WorkflowsWorkflows are a set of are a set of ActivitiesActivities

Workflows run within a Workflows run within a Host Host Process: Process: any application or any application or serverserverDevelopers can build their own Developers can build their own Custom Activity LibrariesCustom Activity Libraries

ComponentsComponentsBase Activity Library:Base Activity Library: Out-of-box Out-of-box activities and base for custom activities and base for custom activitiesactivitiesRuntime Engine:Runtime Engine: Workflow Workflow execution and state managementexecution and state managementRuntime Services:Runtime Services: Hosting Hosting flexibility and communicationflexibility and communication

Page 29: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

29

Workflow BasicsWorkflow BasicsA workflow is a classA workflow is a class

A workflow class may be defined in markupA workflow class may be defined in markup

<?Mapping XmlNamespace="Activities" ClrNamespace="System.Workflow.Activities" Assembly="System.Workflow.Activities" ?>

<SequentialWorkflow x:Class="MyWorkflow" xmlns="Activities" xmlns:x="Definition"> …</SequentialWorkflow>

using System.Workflow.Activities;

public class Workflow1 : SequentialWorkflow{}

Page 30: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

30

Workflow BasicsWorkflow BasicsWorkflow constructor configures contained Workflow constructor configures contained activities (like forms & controls)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";

}}

Page 31: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

31

Workflow Authoring ModesWorkflow Authoring Modes

.NET assembly• ctor defines

workflow

Markup OnlyMarkup Only““Declarative”Declarative”

XAMLXAML

Markup andMarkup andCodeCode

C#/C#/VBVB

Code OnlyCode Only ApplicationApplicationGeneratedGenerated

XAMLXAML C#/C#/VBVB

• XML definesXML definesworkflow structureworkflow structurelogic and data flowlogic and data flow

• XML definesXML definesworkflowworkflow• Code-beside Code-beside defines extra defines extra logic logic

• Code createsCode createsworkflowworkflowin constructorin constructor XAMLXAML C#/C#/

VBVB

App creates App creates activityactivitytree and tree and serializesserializes

Workflow Compilerwfc.exe

C#/VB Compiler

Page 32: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

32

WorkflowsWorkflows

Page 33: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

33

Activity BasicsActivity BasicsAn activity is a step in a workflowAn activity is a step in a workflow

Unit of execution, re-use and composition Unit of execution, re-use and composition

Think of Forms & ControlsThink of Forms & ControlsActivity == ControlsActivity == Controls

Workflows == Forms Workflows == Forms

Activities fall under two broad categoriesActivities fall under two broad categoriesBasicBasic – steps that “do work” – steps that “do work”

CompositeComposite – manage a set of child activities – manage a set of child activities

Activities are classesActivities are classesHave Have propertiesproperties andand eventsevents that are that are programmable within your workflow codeprogrammable within your workflow codeHave Have methodsmethods (e.g. Execute) that are only (e.g. Execute) that are only invoked by the workflow runtimeinvoked by the workflow runtime

Page 34: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

34

Example: A SendMail Example: A SendMail ActivityActivityusing 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"; }}

Page 35: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

35

Activities: An Extensible Activities: An Extensible ApproachApproach

OOB activities, OOB activities, workflow types,workflow types,

base typesbase typesGeneral-General-purposepurposeActivity Activity librarieslibraries

define define workflowworkflow

constructsconstructs

Create/Extend/ Create/Extend/ Compose Compose activitiesactivitiesApp-specific App-specific building blocksbuilding blocksFirst-class First-class citizenscitizens

Base ActivityBase ActivityLibraryLibrary

Custom Custom Activity Activity LibrariesLibraries

Author new activity

Out-of-Box Activities

Extend activity

Compose activities

Vertical-specific Vertical-specific activities & activities & workflowsworkflowsBest-practice IP Best-practice IP & Knowledge& Knowledge

Domain-Domain-Specific Specific

Workflow Workflow PackagesPackages

Compliance

RosettaNet

CRM

IT Mgmt

Page 36: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

36

Combining WCF and WFCombining WCF and WF

Page 37: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

37

Coordinating ServicesCoordinating Services

Workflows are an excellent way to coordinate work across Workflows are an excellent way to coordinate work across multiple servicesmultiple services

Service interaction is modeled using activities in a workflowService interaction is modeled using activities in a workflow

Service interaction can be visualizedService interaction can be visualized

Data can be flowed from one activity and service to anotherData can be flowed from one activity and service to another

Workflows simplify asynchronous service calls and complex Workflows simplify asynchronous service calls and complex message exchange patternsmessage exchange patterns

Parallel execution, delays, time-outs, etc.Parallel execution, delays, time-outs, etc.

Service interaction can easily be modified and dynamically changedService interaction can easily be modified and dynamically changed

Coordinating ServicesCoordinating Services

Message

Message

Page 38: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

38

Implementing ServicesImplementing Servicesusing Workflowusing Workflow

Challenges developing services todayChallenges developing services todayServices are often used together as part of a business process, but are not Services are often used together as part of a business process, but are not explicitly associatedexplicitly associatedServices often front-end, long-running business processesServices often front-end, long-running business processes

Workflows are an excellent way to implement the logic behind servicesWorkflows are an excellent way to implement the logic behind servicesState management across multiple service interactionsState management across multiple service interactionsServices are associated together in a workflow modelServices are associated together in a workflow modelImplementation of services can be transparent Implementation of services can be transparent Enables visibility into the state of the serviceEnables visibility into the state of the serviceConfigurable runtime behavior Configurable runtime behavior

Tracking, persistence, transactions, threading, etc.Tracking, persistence, transactions, threading, etc.

Workflows exposedWorkflows exposedthrough servicesthrough services

Message

Page 39: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

39

The Workflow/Service The Workflow/Service EcosystemEcosystem

Solutions will often combine both Solutions will often combine both approachesapproaches

WorkflowWorkflow

Message

Message

Message

Page 40: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

40

Call To ActionCall To Action

WCF is “no brainer” for future connectivityWCF is “no brainer” for future connectivityUse itUse it

Don’t necessarily need to port to itDon’t necessarily need to port to it

Use WF Use WF Build workflow into your applicationsBuild workflow into your applications

Make you applications more flexible and configurableMake you applications more flexible and configurable

Build workflow enabled servers for other Build workflow enabled servers for other developers to targetdevelopers to target

Build custom activity libraries for others to re-Build custom activity libraries for others to re-useuse

Build solutions on top of workflow enabled Build solutions on top of workflow enabled products like Office 2007products like Office 2007

Page 41: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

41

ResourcesResources

MSDN®MSDN®http://msdn.microsoft.com/winfx/technolhttp://msdn.microsoft.com/winfx/technologies/communication/ogies/communication/

http://msdn.microsoft.com/workflowhttp://msdn.microsoft.com/workflow

Community SiteCommunity Sitehttp://www.netfx3.com/http://www.netfx3.com/

Subscribe to the RSS feed for news & Subscribe to the RSS feed for news & updatesupdates

Find, download, & register ActivitiesFind, download, & register Activities

Find blogs, screencasts, whitepapers, and Find blogs, screencasts, whitepapers, and other resourcesother resources

Download samples, tools, and runtime Download samples, tools, and runtime service componentsservice components

Page 42: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

42

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Page 43: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

43

WCF Code MigrationWCF Code Migration

Page 44: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

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 WCFASMX to WCF

Page 45: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

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 WCFEnterprise Services to WCF

Page 46: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

46

using Microsoft.Web.Services3;using Microsoft.Web.Services3;

[WebService][WebService]class HelloWorld class HelloWorld {{

      

[WebMethod][WebMethod]

        public string Hello (string text)public string Hello (string text) {{

MessageSignature signature = (MessageSignature)MessageSignature signature = (MessageSignature)RequestSoapContext.Current.Security.Elements[0];RequestSoapContext.Current.Security.Elements[0];if (!signature.SigningToken.Principal.IsInRoleif (!signature.SigningToken.Principal.IsInRole ("BUILTIN\Administrators"))("BUILTIN\Administrators"))

                        throw new AuthorizationException("Access denied");throw new AuthorizationException("Access denied");  

                return String.Format("Hello, {0}", text);return String.Format("Hello, {0}", text);        }}}}

Note: Configuration entry changes are requiredNote: Configuration entry changes are required

[OperationContract][OperationContract]

[PrincipalPermission(SecurityAction.Demand, null, "BUILTIN\[PrincipalPermission(SecurityAction.Demand, null, "BUILTIN\Administrators")]Administrators")]

using System.ServiceModel;using System.ServiceModel;

[ServiceContract][ServiceContract]

////

////

////

////////////

////////

WSE to WCFWSE to WCF

Page 47: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

47

class MyQService class MyQService {{ public void ReceiveOrders()public void ReceiveOrders() {{ MessageQueue Queue = new MessageQueue(@".\private$\Books");MessageQueue Queue = new MessageQueue(@".\private$\Books"); XmlMessageFormatter formatter = new XmlMessageFormatter(XmlMessageFormatter formatter = new XmlMessageFormatter( new Type[] { typeof(System.Data.DataSet)});new Type[] { typeof(System.Data.DataSet)}); Queue.Formatter = formatter;Queue.Formatter = formatter; System.Messaging.Message msg = null;System.Messaging.Message msg = null; while((msg= Queue.Receive()) != null)while((msg= Queue.Receive()) != null) {{

DataSet booklist = (DataSet) msg.Body;DataSet booklist = (DataSet) msg.Body; ProcessOrders(booklist);ProcessOrders(booklist);

}} }}

Public void ProcessOrder(DataSet BookList) { ... }Public void ProcessOrder(DataSet BookList) { ... }

}}

using System.Messaging;using System.Messaging;using System.ServiceModel;using System.ServiceModel;

[ServiceContract][ServiceContract]

[OperationContract(IsOneWay = true)][OperationContract(IsOneWay = true)]

////

////

////

////////////////////////////

////////

////

System.Messaging to WCFSystem.Messaging to WCF

Page 48: 1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson Eric.Nelson@microsoft.com Eric.Nelson@microsoft.com Application Architect

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.NET Remoting to WCF