Date post: | 06-Apr-2018 |
Category: |
Documents |
Upload: | patrarobin9157 |
View: | 215 times |
Download: | 0 times |
of 41
8/3/2019 Eric Nelson - Understanding WCF and WF
1/41
1
Understanding WindowsCommunication FoundationandWorkflow Foundation
Eric Nelson [email protected] Architect
Microsoft Ltd
http://blogs.msdn.com/ericnel
mailto:[email protected]://blogs.msdn.com/ericnelhttp://blogs.msdn.com/ericnelmailto:[email protected]8/3/2019 Eric Nelson - Understanding WCF and WF
2/41
2
Windows Communication
Foundation
8/3/2019 Eric Nelson - Understanding WCF and WF
3/41
3
Agenda
Basic Principles of WCFCreating a Service
8/3/2019 Eric Nelson - Understanding WCF and WF
4/41
4
Client Service
Clients and Services
8/3/2019 Eric Nelson - Understanding WCF and WF
5/41
5
Client Service
Endpoints
EndpointEndpoint
Endpoint
Endpoint
8/3/2019 Eric Nelson - Understanding WCF and WF
6/41
6
Client Service
Address, Binding, Contract
CBA
CBA
CBA
ABC
AddressWhere?
ContractWhat?
BindingHow?
8/3/2019 Eric Nelson - Understanding WCF and WF
7/417
Client Service
Behaviors
CBA
CBA
CBA
ABC
B BB
8/3/2019 Eric Nelson - Understanding WCF and WF
8/418
SelectingAddress Binding BehaviorContract
HTTPTransport
TCP
Transport
NamedPipeTransport
MSMQTransport
CustomTransport
WS-SecurityProtocol
WS-RMProtocol
WS-CoordProtocol
DuplexChannel
CustomProtocol
http://...
net.tcp://...
net.pipe://...
net.msmq://...
xxx://...
Throttling
Behavior
MetadataBehavior
ErrorBehavior
CustomBehavior
InstancingBehavior
ConcurrencyBehavior
TransactionBehavior
SecurityBehavior
Request/Response
One-Way
Duplex
net.p2p://...Peer
Transport
Externally visible,per-endpoint
Opaque, per-service,endpoint, or operation
8/3/2019 Eric Nelson - Understanding WCF and WF
9/419
Creating a Service
1. Define Whatto Expose (Contract)2. Implement Contract
3. Define Endpoint(s)
1. Define Howto Expose (Binding)
2. Define Whereto Expose (Address)
4. Host & Run Service
8/3/2019 Eric Nelson - Understanding WCF and WF
10/41
10
ContractsA 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) { ... }}
8/3/2019 Eric Nelson - Understanding WCF and WF
11/41
11
Encoding
Text, Binary, MTOM, Custom
Transport SelectionTCP, HTTP, Named Pipes, Peer Channel, MSMQ, Custom
End-to-End SecurityConfidentiality, Integrity, AuthN, AuthZ, Federation & Infocard
X.509, Username/Password, Kerberos, SAML, XrML, Custom
End-to-End Reliable MessagingTransport-Independent QoS (In-Order / Exactly-Once)
Volatile and Durable Queues for AvailabilityTransactions
Shared Transactions for Synchronous Operations
Transactional Queues for Asynchronous Operations
Binding
8/3/2019 Eric Nelson - Understanding WCF and WF
12/41
12
Addresseshttp://microsoft.com:80/OrderService/WS
https://microsoft.com:443/OrderService/BP
net.tcp://microsoft.com:808/OrderService/TCP
net.pipe://microsoft.com/OrderService/NP
Scheme http, https, net.tcp, net.pipeHost Name microsoft.com
Port (Optional) * 80, 443, 808
Base Path /OrderService/Endpoint Address WS, BP, TCP, NP
* - Port Does Not Apply to Named Pipes
8/3/2019 Eric Nelson - Understanding WCF and WF
13/41
13
Hosting
ServiceHost allows for hosting anywhere
Console applications
Windows applications
Windows services
IIS provides an enterprise class hostingenvironment
Edit a .svc file and point at your service
HTTP transport in IIS 6.0
All transports in IIS 7.0 (Windows Activation
Service)
8/3/2019 Eric Nelson - Understanding WCF and WF
14/41
14
ServiceHost
Allows a WCF Service to be Hosted in AnyAppDomain
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();}
8/3/2019 Eric Nelson - Understanding WCF and WF
15/41
15
Windows Communication
Foundation
8/3/2019 Eric Nelson - Understanding WCF and WF
16/41
16
Windows Workflow
Foundation
8/3/2019 Eric Nelson - Understanding WCF and WF
17/41
17
Agenda
Introduction to Windows WorkflowFoundation
Workflow basics
Activities basics
8/3/2019 Eric Nelson - Understanding WCF and WF
18/41
18
Windows Workflow Foundation
Key Concepts
Host Process
WindowsWorkflow 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 ActivitiesWorkflows run within a HostProcess: any application or serverDevelopers can build their ownCustom Activity Libraries
Components
Base Activity Library: Out-of-boxactivities and base for custom activities
Runtime Engine: Workflow execution
and state managementRuntime Services: Hosting flexibilityand communication
8/3/2019 Eric Nelson - Understanding WCF and WF
19/41
19
Workflow BasicsA workflow is a class
A workflow class may be defined in markup
using System.Workflow.Activities;
public class Workflow1 : SequentialWorkflow
{
}
8/3/2019 Eric Nelson - Understanding WCF and WF
20/41
20
Workflow BasicsWorkflow constructor configures containedactivities (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";
}}
8/3/2019 Eric Nelson - Understanding WCF and WF
21/41
21
Workflow Authoring Modes
.NET assemblyctor defines
workflow
Markup Only
Declarative
XAML
Markup and
Code
C#/VB
Code Only Application
Generated
XAML C#/VB
XML defines
workflow structurelogic and data flow
XML definesworkflow Code-besidedefines extra logic
Code createsworkflow
in constructor XAML C#/VB
App creates activitytree and serializes
Workflow Compilerwfc.exe
C#/VB Compiler
8/3/2019 Eric Nelson - Understanding WCF and WF
22/41
22
Workflows
8/3/2019 Eric Nelson - Understanding WCF and WF
23/41
23
Activity BasicsAn activity is a step in a workflow
Unit of execution, re-use and compositionThink of Forms & Controls
Activity == Controls
Workflows == Forms
Activities fall under two broad categoriesBasicsteps that do work
Composite manage a set of child activities
Activities are classesHave propertiesandevents that are programmablewithin your workflow code
Have methods (e.g. Execute) that are only invoked bythe workflow runtime
E l A S dM il A i i
8/3/2019 Eric Nelson - Understanding WCF and WF
24/41
24
Example: A SendMail Activityusing 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";
}
}
8/3/2019 Eric Nelson - Understanding WCF and WF
25/41
25
Activities: An Extensible Approach
OOB activities,workflow types,base typesGeneral-purposeActivity librariesdefine workflow
constructs
Create/Extend/ComposeactivitiesApp-specificbuilding blocksFirst-class
citizens
Base Activity
Library
Custom Activity
Libraries
Author newactivity
Out-of-BoxActivities
Extendactivity
Composeactivities
Vertical-specificactivities &workflowsBest-practice IP &Knowledge
Domain-SpecificWorkflowPackages
Compliance
RosettaNet
CRM
IT Mgmt
8/3/2019 Eric Nelson - Understanding WCF and WF
26/41
26
Combining WCF and WWF
8/3/2019 Eric Nelson - Understanding WCF and WF
27/41
27
Coordinating Services
Workflows are an excellent way to coordinate work across multipleservices
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 messageexchange patterns
Parallel execution, delays, time-outs, etc.
Service interaction can easily be modified and dynamically changed
Coordinating Services
Message
Message
8/3/2019 Eric Nelson - Understanding WCF and WF
28/41
28
Implementing Servicesusing Workflow
Challenges developing services todayServices are often used together as part of a business process, but are not explicitlyassociated
Services often front-end, long-running business processes
Workflows are an excellent way to implement the logic behind servicesState management across multiple service interactions
Services are associated together in a workflow modelImplementation of services can be transparent
Enables visibility into the state of the service
Configurable runtime behaviorTracking, persistence, transactions, threading, etc.
Workflows exposedthrough services
Message
8/3/2019 Eric Nelson - Understanding WCF and WF
29/41
29
The Workflow/ServiceEcosystem
Solutions will often combine bothapproaches
Workflow
Message
Message
Message
8/3/2019 Eric Nelson - Understanding WCF and WF
30/41
30
Call To Action
WCF is no brainer for future connectivityUse it
Dont 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 totarget
Build custom activity libraries for others to re-use
Build solutions on top of workflow enabled productslike Office 12
8/3/2019 Eric Nelson - Understanding WCF and WF
31/41
31
Resources
MSDN
http://msdn.microsoft.com/webservices/indigo/http://msdn.microsoft.com/workflow
Community Site
http://www.windowsworkflow.net
http://www.windowscommunication.netSubscribe to the RSS feed for news &updates
Find, download, & register Activities
Find blogs, screencasts, whitepapers, andother resources
Download samples, tools, and runtime
service components
ForumsAsk questions in the forumshttp://www.WindowsWorkflow.net/Forums
http://www.windowscommunication.net/Forums
http://msdn.microsoft.com/webservices/indigo/http://msdn.microsoft.com/workflowhttp://www.windowsworkflow.net/http://www.windowscommunication.net/http://www.windowsworkflow.net/Forumshttp://www.windowscommunication.net/Forumshttp://www.windowscommunication.net/Forumshttp://www.windowsworkflow.net/Forumshttp://www.windowscommunication.net/http://www.windowsworkflow.net/http://msdn.microsoft.com/workflowhttp://msdn.microsoft.com/webservices/indigo/8/3/2019 Eric Nelson - Understanding WCF and WF
32/41
32
2005 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
8/3/2019 Eric Nelson - Understanding WCF and WF
33/41
33
Wrap Up
Exploring WinFX and VistaGetting help from Microsoft
8/3/2019 Eric Nelson - Understanding WCF and WF
34/41
34
Exploring WinFX and Vista
WinFX works on both Windows XP and VistaBoth are Beta!
Currently at February CTP of each
A CTP is not a Beta
January CTP of WinFX is Beta 2 of WCF andWF can go-live on it
WinFX public download
Vista MSDN Subscribers
http://blogs.msdn.com/ericnel
http://blogs.msdn.com/ericnel/articles/545219.aspx
http://blogs.msdn.com/ericnelhttp://blogs.msdn.com/ericnel/articles/545219.aspxhttp://blogs.msdn.com/ericnel/articles/545219.aspxhttp://blogs.msdn.com/ericnel8/3/2019 Eric Nelson - Understanding WCF and WF
35/41
35
Early Adoption Assistance
Open to managed ISVsISV Certified or PAM/TPAM managed
Commit to develop on the Betas
Technical Benefits20 hours of support
Class room based training (3 day)
Opportunities to attend 2 day labs (most active)
Other
Interested contact your PAM/TPAM
If no PAM/TPAM and certified, [email protected] and
mailto:[email protected]:[email protected]:[email protected]:[email protected]8/3/2019 Eric Nelson - Understanding WCF and WF
36/41
36
WCF Code Migration
8/3/2019 Eric Nelson - Understanding WCF and WF
37/41
37
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/3/2019 Eric Nelson - Understanding WCF and WF
38/41
38
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
8/3/2019 Eric Nelson - Understanding WCF and WF
39/41
39
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);
}}
[OperationContract][PrincipalPermission(SecurityAction.Demand, null,"BUILTIN\Administrators")]
using System.ServiceModel;[ServiceContract]
////
//
//////////
WSE to WCF
8/3/2019 Eric Nelson - Understanding WCF and WF
40/41
40
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
8/3/2019 Eric Nelson - Understanding WCF and WF
41/41
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