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
48
Embed
1 Understanding Windows Communication Foundation and Workflow Foundation Eric Nelson [email protected][email protected] Application Architect.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
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
Windows Windows Communication Communication FoundationFoundation
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
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?
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
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
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. }}
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
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; }}
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
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)
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();}
20
Windows Windows Communication Communication FoundationFoundation
Svctraceviewer.exeSvctraceviewer.exe
Svcconfigeditor.exeSvcconfigeditor.exe
+ so much more+ so much more
21
Windows Workflow Windows Workflow FoundationFoundation
22
AgendaAgenda
Introduction to Windows Workflow Introduction to Windows Workflow FoundationFoundation
Workflow basics Workflow basics
Activities basicsActivities basics
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
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
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….
26
Why Workflow Why Workflow Technology?Technology?
Long running and stateful behaviorLong running and stateful behavior
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
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
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
App creates App creates activityactivitytree and tree and serializesserializes
Workflow Compilerwfc.exe
C#/VB Compiler
32
WorkflowsWorkflows
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
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; }
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
36
Combining WCF and WFCombining WCF and WF
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
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.
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.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. }}