08 Wcf Services

download 08 Wcf Services

of 23

Transcript of 08 Wcf Services

  • 8/9/2019 08 Wcf Services

    1/23

    ServicesusingWCF

    MartinKroppUniversityofAppliedSciencesNorthwesternSwitzerland

  • 8/9/2019 08 Wcf Services

    2/23

    LearningTargets You

    knowthedesigngoalsofWindowsCommunicationFoundation

    canexplainthearchitectureofWCF canexplaintheABCofWindowsCommunicationFoundation

    candevelopservicesusingWCF

    canuseservicesthroughdifferentcommunicationchannels

    WindowsCommunication Foundation,v1.0 InstituteforMobileandDistributedSystems,M.Kropp 2

  • 8/9/2019 08 Wcf Services

    3/23

    Content

    WCFBasics MainConcepts

    Addresses

    Contracts

    Behaviour

    Practice

    WindowsCommunicationFoundation,v1.0 3InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    4/23

    WCFFundamentals WindowsCommunicationFoundations

    Isaruntimeformessagebasedcommunication

    DevelopmentAPI

    Forcreatingsystemsthatsendmessagesbetweenservicesandclients

    UnifiedAPIacrossdifferenttransportmechanisms

    Forapplicationsthatcommunicatewithother

    applications Onthesamecomputersystem

    Onexternalcomputersystem Inanothercompanyaccessibleovertheinternet

    WindowsCommunication Foundation,v1.0 Institutefor Mobileand DistributedSystems,M.Kropp 4

  • 8/9/2019 08 Wcf Services

    5/23

    TheFourTenetsofService-Orientation

    Servicesandconsumersareindependentlyversioned,deployed,operated,andAutonomousEvolution

    Developersopt-intoconsuming,exposing,

    anddefiningpublic-facingservicefaade.

    Boundaries

    areExplicit

    WindowsCommunication Foundation,v1.0 InstituteforMobileandDistributedSystems,M.Kropp 5

    secured.

    Dataneverincludesbehavior;Objectswithdataandbehaviorarealocalphenomenon.

    Shareschema&contract,notclass

    Capabilitiesandrequirementsrepresentedbyauniquepublicname;Usedtoestablishservicesuitability.

    Compatibilitybasedonpolicy

  • 8/9/2019 08 Wcf Services

    6/23

    Aunifiedprogrammingmodelforbuildingservice-orientedapplicationsontheWindowsplatform

    Unifiestodaysdistributedtechnologystacks

    Composablefunctionality

    Appropriateforuseon-machine,intheintranet,andcrosstheInternet

    WCFDesignGoals

    Unification

    WS-*interoperabilitywithapplicationsrunningonotherplatforms

    Interoperabilitywithtodaysdistributedstacks

    Interoperability&Integration

    Service-orientedprogrammingmodel

    Supports4tenetsofservice-orientation

    Improvedeveloperproductivity

    ProductiveService-Oriented

    Programming

    WindowsCommunicationFoundation,v1.0 6InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    7/23

    Caller Service

    CallersandServices

    Messa es

    WindowsCommunicationFoundation,v1.0 7InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    8/23

    Caller Service

    Endpoints

    EndpointEndpoint

    Endpoint

    n po n

    WindowsCommunicationFoundation,v1.0 8InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    9/23

    Service

    CBA

    Caller

    TheABCofWCF

    ABC

    CBA

    Address

    Where?

    Contract

    What?

    Binding

    How?

    WindowsCommunicationFoundation,v1.0 9InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    10/23

    WCFArchitecture:MessagingRuntime

    Contract

    and

    Behaviors

    ClientService

    Dispatcher

    Transport

    Encoder

    Protocol(s)

    Transport

    Encoder

    Protocol(s)

    Binding

    Address

    WindowsCommunicationFoundation,v1.0 10InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    11/23

    Adresses Defineswhere aserviceislocated

    SpecifiesaURIwheretheserviceislocated Relativeorabsolute

    Addressconsistof Scheme

    HTTP,TCP,Namedpipes,MSMQ

    [Port] Path

    Examples http://www.mystore.com/StoreFront

    net.tcp://mycomputer:9000/StoreFront

    WindowsCommunication Foundation,v1.0 InstituteforMobileandDistributedSystems,M.Kropp 11

  • 8/9/2019 08 Wcf Services

    12/23

    Contracts Defineswhat aservicecommunicate

    ServiceContracts

    Describetheoperationsaservicecanperform

    MapCLRtypestoWSDL

    DataContracts

    Describesadatastructure

    MapsCLRtypestoXSD

    MessageContracts

    Definesthe(applicationspecific)structureofthemessageonthewire

    MapsCLRtypestoSOAPmessages

    WindowsCommunicationFoundation,v1.0 12InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    13/23

    WaystoTalkOneWay

    Request-Reply

    Duplex(Dual)

    Client Service

    OneWay: Datagram-styledelivery

    Request-Reply ImmediateReplyonsamelogicalthread

    Duplex Replylaterandonbackchannel(callback-style)

    WindowsCommunicationFoundation,v1.0 13InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    14/23

    ServiceContract

    [[[[ServiceContractServiceContractServiceContractServiceContract]]]]

    public interface ICalculator{

    [[[[OperationContractOperationContractOperationContractOperationContract]]]]

    int DoMath int a int b strin o

    WindowsCommunication Foundation,v1.0 InstituteforMobileandDistributedSystems,M.Kropp 14

    // Not exposed as part of the external contract :-)

    void MethodRequiredForImplementation(bool b);

    }

  • 8/9/2019 08 Wcf Services

    15/23

    DataContract

    [[[[DataContractDataContractDataContractDataContract]]]]

    public class ComplexNumber

    {[[[[DataMemberDataMemberDataMemberDataMember]]]]public double Real = 0.0D;

    [[[[DataMemberDataMemberDataMemberDataMember]]]]public double Imaginary = 0.0D;

    public ComplexNumber(double r, double i){

    this.Real = r;this.Imaginary = i;

    }

    }

    WindowsCommunicationFoundation,v1.0 15InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    16/23

    MessageContract

    [[[[MessageContractMessageContractMessageContractMessageContract]]]]

    public class ComplexProblem

    {[[[[MessageHeaderMessageHeaderMessageHeaderMessageHeader(Name="Op",(Name="Op",(Name="Op",(Name="Op", MustUnderstandMustUnderstandMustUnderstandMustUnderstand=true)]=true)]=true)]=true)]public string operation;

    [[[[MessageBodyMemberMessageBodyMemberMessageBodyMemberMessageBodyMember]]]]pu c Comp exNum er n1;

    [[[[MessageBodyMemberMessageBodyMemberMessageBodyMemberMessageBodyMember]]]]public ComplexNumber n2;

    [[[[MessageBodyMemberMessageBodyMemberMessageBodyMemberMessageBodyMember]]]]public ComplexNumber solution;

    // Constructors

    }

    WindowsCommunicationFoundation,v1.0 16InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    17/23

    Binding Describeshow aservicecommunicates

    Specifiessetofbindingelements

    Transport;http,tcp,np,msmq Encodingformat;text,binary,MTOM,...

    Securityrequirements

    Transactionrequirements

    Setofpredefinedstandardbindings Canbecustomized

    Custombinding

    WindowsCommunication Foundation,v1.0 InstituteforMobileandDistributedSystems,M.Kropp 17

  • 8/9/2019 08 Wcf Services

    18/23

    Behavior Modifiesorextendsserviceorclientruntime

    behavior

    Examples Instancing;Singleton,PrivateSession,SharedSession,

    PerCall

    Concurrency;Multiple,Reentrant,Single Throttling;connections,threading

    Metadatacustomization

    Transactions;AutoEnlist,Isolation,AutoComplete

    WindowsCommunication Foundation,v1.0 InstituteforMobileandDistributedSystems,M.Kropp 18

  • 8/9/2019 08 Wcf Services

    19/23

    Bindings&Behaviors:Security

    Service

    CBA

    Client

    ABC

    CBA

    BeBe

    Bindings InsertClaims inMessages

    BehaviorsImplement

    Security Gates

    WindowsCommunicationFoundation,v1.0 19InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    20/23

    ConfiguringServices:DefiningEndpoints

    " "=

    bindingSectionName="basicProfileBinding"contractType="ICalculator" />

    WindowsCommunicationFoundation,v1.0 20InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    21/23

    ConfiguringWCF:SpecifyBindings

    WindowsCommunicationFoundation,v1.0 21InstituteforMobileandDistributedSystems,M.Kropp

  • 8/9/2019 08 Wcf Services

    22/23

    FeaturesSummary

    Address Binding BehaviorContract

    HTTPTransport

    WS-SecurityProtocol

    WS-RM

    http://...

    Throttling

    Behavior

    InstancingBehavior

    ConcurrencyBehavior

    Request/Response

    net.p2p://...Peer

    Transport

    WindowsCommunication Foundation,v1.0 Institutefor Mobileand DistributedSystems,M.Kropp 22

    Transport

    NamedPipeTransport

    MSMQ

    Transport

    CustomTransport

    Protocol

    WS-CoordProtocol

    Duplex

    Channel

    CustomProtocol

    net.tcp://...

    net.pipe://...

    net.msmq://...

    xxx://...

    MetadataBehavior

    ErrorBehavior

    CustomBehavior

    TransactionBehavior

    SecurityBehavior

    One-Way

    Duplex

    Externallyvisible,per-endpoint Opaque,per-service,endpoint,oroperation

  • 8/9/2019 08 Wcf Services

    23/23

    BuildingaWCFapplication

    ApplicationDesign

    Service

    1. DefineContracts

    2. ImplementContracts

    3. DefineEndpoints

    4. Host&RunService Client

    1. GenerateProxyfromMetadata

    2. Implement&RunClient

    WindowsCommunicationFoundation,v1.0 23InstituteforMobileandDistributedSystems,M.Kropp