660 likes | 853 Views
Windows Server 2008 – Windows Communication Foundation. Dave Allen ISV Application Architect Developer and Platform Group Microsoft UK. Agenda. WCF Architecture Contracts Bindings Address Behaviours Windows Process Activation Service Hosting WF from WCF in IIS 7.0. A. A. A. B. B.
E N D
Windows Server 2008 – Windows Communication Foundation Dave Allen ISV Application Architect Developer and Platform Group Microsoft UK
Agenda • WCF Architecture • Contracts • Bindings • Address • Behaviours • Windows Process Activation Service • Hosting WF from WCF in IIS 7.0
A A A B B B C C C Endpoint ClientChannel C B A Endpoint Endpoint Endpoint Bv Bv Bv Bv ServiceHost Address Where? Binding How? Contract What? Endpoints Runtime Behaviours Address, Binding, Contract Clients and Services Metadata Client Service Endpoint
Contracts • Service Contract • Describes the service endpoints and the operations that can be performed on those endpoints. • Data Contract • Describes the message serialization. Maps CLR types to schema definition. • Message Contract • Describes structure of message on the wire. Provides control over the structure of the message.
Service Contract [ServiceContract] public interface IHello { [OperationContract] string Hello(string name); } public classHelloService : IHello { public string Hello(string name) { return “Hello ” + name; } }
Service Contract: OneWay [ServiceContract] public interface IIncomingMessage { [OperationContract(IsOneWay=true)] void SendMessage(string name); }
Service Contract: Duplex [ServiceContract(CallbackContract=typeof(IOutgoingMessage))] public interface IIncomingMessage { [OperationContract(IsOneWay=true)] void SendMessage(string name); } public interface IOutgoingMessage { [OperationContract(IsOneWay=true)] void ReceiveMessage(string s); }
Service Contract: Faults [ServiceContract] public interface IHello { [OperationContract] [FaultContract(typeof(InvalidNameException))] string Hello(string name); } public string Hello(string name) { if(name != “Dave”) { throw new FaultException<InvalidNameException>( new InvalidNameException(“Wrong name")); } }
Data Contract [ServiceContract] public interface IHello { [OperationContract] string Hello(HelloMessage msg); } [DataContract] public classHelloMessage { [DataMember(Name=“From”)] public string from; [DataMember(Name=“From”, IsRequired=true)] public string to; [DataMember] public string message; }
Message Contract [DataContract] [MessageContract] public classHelloMessage { [DataMember] [MessageBody] public string from; [DataMember] [MessageHeader] public string to; [DataMember] [MessageBody] public string message; }
Binding HTTP Security RM TX Text Bindings Transport Encoders Protocol TCP HTTP Text WS-* Binary MSMQ Pipes MTOM Custom Custom Custom
Standard Bindings T = Transport Security | S = WS-Security | O = One-Way Only
ASMX/WSE3 WCF MSMQ WCF WCF WCF ASMX/WSE3 WCF MSMQ WCF Interop Bindings WS-* Protocols *Binding *Binding WS-* Protocols Http/WSBinding WS-* Protocols Http/WSBinding MSMQ Protocol MSMQBinding MSMQ Protocol MSMQBinding
Choosing Bindings • Bindings have semantics • Session, Duplex, Transaction Flow, Transacted Read, Queued Delivery, Ordered, Assurances • Asserting Semantic Requirements in Code • [ServiceContract] • [DeliveryRequirements] • Customization • ‘Tweak’ existing standard bindings • Create completely new bindings
Addresses http://microsoft.com:80/OrderService/WS https://microsoft.com:443/OrderService/BP net.tcp://microsoft.com:808/OrderService/TCP net.pipe://microsoft.com/OrderService/NP * - Port Does Not Apply to Named Pipes
Service Hosting Options • ServiceHost allows for hosting anywhere • Console applications • Windows applications • Windows services • IIS provides a scalablehost environment • Edit a .svc file and point at your service • Only HTTP transports in IIS 6.0 • All transports in IIS 7.0 (Windows Process Activation Service)
Service Hosting Self-host class HelloHost { static void Main(string[] args) { ServiceHosthost = new ServiceHost(typeof(HelloService)); host.Open(); // Wait until done accepting connections Console.ReadLine(); host.Close(); } } IIS-host http://localhost/HelloService/HelloService.svc <%@ServiceHost language=c# Service=“HelloService" %>
Service Configuration <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name=“HelloService”> <endpoint address=“” binding=“basicHttpBinding" contract="IHello" /> </service> </services> </system.serviceModel> </configuration>
demo Windows Communication Foundation
Behaviours • Behaviours cover the system semantics • Service features • Concurrency • Instancing • Transactions • Impersonation • Deployment features • Throttling • Metadata exposure
Instancing • Per Call • Single • Private Session • Shared Session
Concurrency • Multiple • Reentrant • Single
demo Windows Communication Foundation
WAS Activation • Activation and health of worker process is managed by Windows Process Activation Service • Provides “external” monitoring and recycling • Activate over TCP, Named Pipe, MSMQ, or HTTP • Provides high availability, managed process for web service based applications
WAS • In IIS 7.0, Windows Process Activation Service (WAS) manages application pool configuration and worker processes instead of WWW Service in IIS 6.0. This enables the same configuration and process model for HTTP and non-HTTP sites. • Additionally, you can run WAS without WWW Service if you do not need HTTP functionality. For example, you can manage an WCF service through a listener, such as NET.TCP, without running the WWW Service if you do not need to listen for HTTP requests in HTTP.sys.
Adding net.tcp binding to IIS 7.0 • Add net.tcp binding to “Default Web Site” • appcmd.exe set site "Default Web Site" – +bindings.[protocol='net.tcp', bindingInformation='808:*'] • Add a new application • appcmd add app /site.name:"Default Web Site" /path:/WasDemo /physicalpath: c:\Inetpub\wwwRoot\WasApplication • Enable protocols for the application • appcmd.exe set app "Default Web Site/WasApplication" /enabledProtocols: http,net.pipe,net.tcp,net.msmq
demo Windows Communication Foundation
Hosting WF from WCF in IIS 7.0 • Implement a ServiceHost extension • Override Attach and Detach to start and stop the WorkflowRuntime • Derive a new ServiceHost that loads the loads the ServiceHost extension • Derive a new ServiceHostFactory to load the new ServiceHost • Add the Factory attribute to .svc file
demo Windows Communication Foundation
.NET Framework 3.5 “Orcas” • WF & WCF Integration • WCF partial trust support • WCF JSON Serialization • webHttpBinding to enable • Integrate with ASP.NET AJAX Framework • WCF POX/REST support • Programming against resource-centric applications • webHttpBinding to enable • WCF RSS/Atom support • Add SyndicationBehavior to endpoint Code Name “Orcas”
WCF Features Summary Address Binding Contract Behavior Request/Response InstancingBehavior HTTPTransport WS-SecurityProtocol ConcurrencyBehavior http://... Peer Transport net.p2p://... Throttling Behavior WS-RMProtocol TCP Transport net.tcp://... MetadataBehavior NamedPipeTransport WS-CoordProtocol One-Way net.pipe://... Error Behavior TransactionBehavior MSMQTransport DuplexChannel net.msmq://... CustomBehavior SecurityBehavior Duplex CustomTransport CustomProtocol xxx://... Externally visible, per-endpoint Opaque, per-service, endpoint, or operation
Resources • MSDN WCF home page http://msdn2.microsoft.com/en-us/netframework/aa663324.aspx • WCF community site http://wcf.netfx3.com/ • Great WAS article for developers http://msdn.microsoft.com/msdnmag/issues/07/09/WAS/
Windows Server 2008 – Windows Workflow Foundation Dave Allen ISV Application Architect Developer and Platform Group Microsoft UK
Agenda • What is Windows Workflow Foundation? • Architecture & Core concepts • Building Workflows • Building Activities • Runtime Services
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 • Bring declarative workflow to any .NET developer • Fundamental part of the Office 2007 • Strong workflow partner & solution ecosystem
What is a workflow? A set of activities that coordinate people and / or software... EscalateToManager CheckInventory Example activities…. …organized into some form of workflow. Or a state diagram…. or based on rules. Like a flowchart….
Windows Workflow Foundation Visual Designer KeyConcepts A Workflow • Workflows are a set of Activities • Workflows run within a Host Process:any application or server • Developers can build their own Custom Activity Libraries An Activity Custom Activity Library Components Windows Workflow Foundation • Base Activity Library:Out-of-box activities and base for custom activities Base Activity Library • Runtime Engine:Workflow execution and state management Runtime Engine • Runtime Services:Hosting flexibility and communication Runtime Services • Visual Designer: Graphical and code-based construction Host Process
C#/VB C#/VB C#/VB Workflow Authoring Modes Application Generated Markup and Code Markup Only “Declarative” Code Only App creates activity tree and serializes XOML XOML • Code creates • workflow • in constructor • XML defines • workflow • Code-beside • defines extra logic • XML defines • workflow structure • logic and data flow XOML Workflow Compiler wfc.exe • .NET assembly • ctor defines • workflow C#/VB Compiler
State1 State2 Flexible Control Flow State Machine Workflow Sequential Workflow External events drive processing order Sequential structure prescribes processing order Step1 Event Step2 Event • Prescriptive, formal • Automation scenarios • Flowchart metaphor • Reactive, event-driven • Skip/re-work, exception handling • Graph metaphor Rules-driven Activities Rule1 Step1 Rules + data state drive processing order Data Step2 Rule2 • Data-driven • Simple Conditions, complex Policies • Constrained Activity Group
Order Processing Example On Order Completed On Order Processed On Order Created Waiting to Create Order Order Created Order Processed On Order Completed On Order Shipped On Order Shipped Order Shipped Order Completed On Order Completed
What are Activities? • An activity is a step in a workflow • Has properties and events that are programmable within your workflow code • Has methods (e.g. Execute) that are only invoked by the workflow runtime • 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
Base Activity Library • Base Activities get you started… • Designed for modeling control flow & communications • IfElse, Delay, While, State, etc. • InvokeWebService, InvokeMethod, etc. • Custom activities can derive from the Base Activities • Base Activities have been built using the same framework that’s available to you as developers
Domain-SpecificWorkflow Packages Compliance CRM Extend activity Compose activities RosettaNet Author new activity IT Mgmt • Vertical-specificactivities & workflows • Best-practice IP &Knowledge Activities: An Extensible Approach Custom ActivityLibraries Base Activity Library Out-of-Box Activities • OOB activities,workflow types,base types • General-purpose • Activity libraries define workflow constructs • Create/Extend/Compose activities • App-specificbuilding blocks • First-class citizens
Why build custom activities? • Activity is unit of: • Execution • Reuse • Composition • Enable workflow modeling • Custom activity examples • SendEmail, FileSystemEvent, etc. • Write custom activities for • Reusing workflow logic • Integrating with technologies • Modeling advanced control flows • Modeling various workflow styles Workflow Execution Logic Simplicity Code Activity InvokeWebService Activity InvokeMethod & EventSink Custom Activities Flexibility
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) { // 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"; } }
Activity Component Model • Each activity has an associated set of components • Components are associated through attributes on the Activity Definition Designer Activity Behaviors Validator // Companion classes [Designer(typeof(MyDesigner))] [CodeGenerator(typeof(MyCodeGen))] [Validator(typeof(MyValidator))] // Behaviors [SupportsTransaction] public class MyActivity: Activity {...} Serializer Code Generator Required Optional (defaults provided)