Windows Communication Foundation Ch. Vishwa Mohan M.Sc., M.Tech Freelance Software Consultant & Corporate Trainer
Introducing WCF WCF  Programming Life Cycle WCF  Serialization Messaging Pattern WCF Bindings Hosting a WCF Service WCF Configuration Behaviors WCF Security WCF Transactions WCF Reliable Sessions WCF Queuing Agenda
WCF Introduction Windows Communication Foundation
Moving from Objects to Services Service Oriented Architecture Concepts WCF Fundamental Concepts WS-* Standards and their relationship.  WCF Architecture WCF Endpoints WCF Address, Binding and Contract WCF Introduction
From Objects to Services Polymorphism Encapsulation Subclassing Message-based Schema+Contract+Policy Broad Interop Location Transparent Tight Coupling Runtime Metadata Object-Oriented Service-Oriented Component-Oriented 1980s 2000s 1990s
What is a SOA ?  Service-Oriented Architecture (SOA) is an approach to loosely coupled, protocol independent, standards-based distributed computing where software resources available on the network are considered as Services.  SOA represents business functions as shared, reusable services.  SOA is not a product but an architectural paradigm.  SOA Characteristics:   The software components in a SOA are services based on standard protocol.  Services in SOA have minimum amount of interdependencies. Communication infrastructure used within an SOA should be designed to be independent of the underlying protocol layer. Share Schema and Contract, not Class/database Offers coarse-grained business services, as opposed to fine-grained software-oriented function calls. Uses service granularity to provide effective composition, encapsulation and management of services. A fully Implemented SOA Provides the ability to rapidly and dynamically compose applications, services and even complete processes.
What is a Service ?  Services are reusable units providing business functionality that are… Clearly defined using standard policies, practice and framework.  Clearly described (usually with XML).  Autonomous Abstraction of the underlying business logic and functionality.  Functionality exposed via structured messaging scheme.  Not XML centric, Not HTTP centric.  JSON, XML, SOAP, Images etc., over TCP, HTTP, Name Pipes, MSMQ, etc.,  Messages sent and received.  Moves from a client/server model to a sender/receiver model.  Rich communication pattern Versioning Independency.  Service orientation provides the benefits of loosely coupled, message-oriented programming. Loose coupling  is a requirement  not a suggestion
Four Tenets of Service Orientation SERVICE ORIENTATION Compatibility Based On Policy Share Schema & Contract, Not Class Services Are Autonomous Boundaries Are Explicit
The Webservice technology is stimulated (inspired) by SOA. Webservices and services are not identical.  Two critical characteristics are realized for SOA development are:  Services are truly independent.  They can be managed. Management includes many functions including, Security, Deployment, Logging, Dynamic rerouting and Maintenance  The connectivity Imperatives:   Interoperability and Integration.  Secure, Reliable and Transacted Messages.  Decoupled Dynamic Applications.  WCF will be the foundation for service oriented applications built on top of the .NET framework.  Service Oriented Architecture (SOA)
SOA Implementation in WCF Boundaries  are Explicit Services are autonomous Share schema & contract, not class Compatibility  based on policy Developers opt-in to consuming, exposing,  and defining public-facing service façade. Services and consumers are independently versioned, deployed, operated, and secured . Data never includes behavior;  Objects with data and behavior are  a local phenomenon. Capabilities and requirements represented  by a unique public name;  Used to establish service suitability.
Anatomy of a Service ?  A service use a channel to communicate. Through channel messages are sent and received.  The messages are build according to predefined contract with data according to predefined schema.  Service can use Policies indicating what and how the client should behave.
How to build Service Oriented Applications?   “ What API should I use?” “ How do I build service-oriented systems?” “ How can I send messages securely & reliably?” “ How do I build dynamic, decoupled applications?”
An API for communicating between applications and services. Provides  secure ,  reliable , and  transacted  messaging along with  interoperability. Unifies  a broad array of distributed systems capabilities in an extensible architecture. Spans  transports ,  security  systems,  messaging  patterns,  encodings ,  network  topologies, and  hosting  models. WCF combines the best of all existing Microsoft distributed computing stacks.  WCF  uses WS-* standards for interoperability and .NET value-add for performance and integration with existing solutions WCF is the future of distributed computing.  What is WCF ?
Extending the .NET Framework WCF Presentation Data Communication Windows Forms ASP.NET SQL Server Compact Framework Console & NT Service … J# C++ C# VB Base App Services Security Configuration Deployment & Management Visual Studio 2008
Windows Communication Foundation INTEROPERABILITY PRODUCTIVITY SERVICE-ORIENTED DEVELOPMENT Broad Support for WS-* specifications Compatible with existing MS distributed application technologies Unifies today’s distributed technologies Attribute-based development Visual Studio Integration Enables development of loosely-coupled services Config-based communication
WCF Unified Programming Model ( Supersets Existing Technologies ) Interop with other platforms ASMX Attribute-  Based Programming Enterprise Services WS-* Protocol Support WSE 2/3 Message- Oriented Programming MSMQ Extensibility Location transparency .NET Remoting Supersets Existing Technologies
WCF address range of challenges for communicating applications: Unification of existing .NET Framework Communication technologies.  Support for cross-vendor interoperability.  Explicit Service Orientation.   WCF address the following unified distributed technologies: Web Services (ASPX) .NET Remoting WSE Enterprise Services MSMQ WCF supports large set of WS-* specifications. So it provides reliability, security, and transactions when communicating with any platform that also supports these specifications.  With WCF also achieve high performance with binary encoding.  Unified Programming Model
WS-* Protocol Support Security WS-Security WS-Trust WS-Secure  Conversation Messaging SOAP, WS-Addressing, MTOM Reliability WS-Reliable Messaging Transactions WS-Atomic Transactions WS-Coordination Metadata WSDL, WS-Policy WS-MetadataExchange WCF supports all the specifications shown in the below fig:  XML
Distributed computing/communications platforms need to interoperate with the technologies different vendors offer. Likewise,  security must also be interoperable .  To enable interoperable security systems a few notable standards have been proposed by Webservice industry. WS-Security WS-Trust WS-SecureConversation WS-SecurityPolicy All the above standards defines addition to SOAP messages for providing authentication, data integrity and data piracy.  WCF also provides support for Kerberos, NTLM, Username, Certificates supported as credential tokens.  SAML Claims support.  WCF Security
Support for  WS-AtomicTransaction  and  WS-Coordination .  Provides distributed transaction enlistment with commit / rollback.  Automatic flow provided by transaction scope.  Allows using two-phase commit transaction with SOAP based message exchanges.  WCF Transaction
Reliable messaging is how a reliable messaging source transfers messages reliably to a reliable messaging destination. Supports  WS-ReliableMessaging . It defines addition to the SOAP header that allows reliable end to end communication.  Provides mechanism to guarantee delivery via acknowledgement protocol.  Note: Retries can be very slow.  WCF Reliability
WS-* Composability and Message Anatomy
Investment Protection SIDE-BY-SIDE Interop UPGRADE Side-by-side co-existence with existing distributed technologies. Smooth upgrade of existing code to WCF Seamless communications with application built on existing technologies
WCF is Microsoft’s unified programming model for building service-oriented applications.  WCF enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments. WCF is implemented primarily as a set of classes on top of .NET Framework CLR.  WCF’s fundamental communication mechanism is SOAP-based WebServices.  WCF Introduction  Caller Service Service 1 Service 2 Message Message All messages are SOAP based
SOAP is XML based protocol providing message construct.  Presently 2 SOAP versions are in use.  SOAP 1.1 is built on XML SOAP 1.2 is built on XML Infoset.  A SOAP message is composed of:  An Envelop.  Within an envelop optional header section and mandatory body.  Within a header zero or more header blocks.  What is SOAP ?  <S:Envelope> <S:Header> <n:HeaderBlock>  .  .  . </n:HeaderBlock> </S:Header>  <S:Body>  . . .  </S:Body> </S:Envelope>
Example of Simple SOAP Envelope <?xml version=&quot;1.0&quot;?>  < soap:Envelope  xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot;  soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;>  < soap:Heade r>  <m:Trans xmlns:m=&quot;http://www.w3schools.com/transaction/&quot;  soap:mustUnderstand=&quot;1&quot;>234</m:Trans>  </ soap:Header > < soap:Body  xmlns:m=&quot;http://www.example.org/stock&quot;>  <m:GetStockPrice>  <m:StockName>IBM</m:StockName>  </m:GetStockPrice>  </ soap:Body > </ soap:Envelope >
A service is a construct that exposes one or more endpoints, each of which exposes one or more service operations.  Endpoints are defined for communication between services.  The  endpoint  of a service specifies:  An  address  where the service can be found. It is basically a URI.  A  binding  that specifies how a client communicate with the endpoint.  Finally  a  contract  that defines the functionality provided by the service to its clients.  End Points Caller Service Message Endpoint Endpoint Endpoint
A endpoint can send and receive messages independent of transport . The endpoint of a service can be specified either imperatively through code or declaratively through configuration file.  The endpoint represented in WCF object model by  ServiceEndpoint  class.  Each endpoint is made up of three elements:  Address:  It is a basically URI.   In WCF object model this address is represented    by  EndpointAddress . Binding:  It describes how a service communicate with the partners. So it consists of collection of details such as transport method, encoding, reliability requirements, and security considerations.  Represented by  Binding  class. WCF Creates channel stack to satisfy the using binding.  Contract:  It consists of collection of operations that endpoint expose to the outside world. Represented by  ContractDescription  class.  End Points
Address, Binding and Contract Caller Service Message Address Binding Contract (Where) (How) (What) There are two ways to specify  endpoint address  for a service in WCF.  You can specify an  absolute address  for each endpoint associated with service.  You can provide a  base address  for the ServiceHost of a service and specify an address for each endpoint relative to this base address.   A B C A B C A B C
Defines  where  a service is located.  Specifies a URI where the service is located.  Relative or Absolute The Address of endpoint represented in WCF by  EndpointAddress  class. It consists basically  URI , an  Identity  and collection of optional  Headers .  Address consists of:  Scheme ( HTTP, TCP, Named Pipes, MSMQ) Machine (www.visitech.com) [Port] : (optional 1024) Path: MbusOpcServer.svc/secureEP Examples:  http://ww.visitech.com:1024/MbusOpcServer.svc net.tcp://visitech.com:1024/MbusOpcServer.svc WCF Address
Describes  how   a service communicates Specifies set of binding elements Transport; http, tcp, np, msmq Encoding format; text, binary, MTOM, ... Security requirements Reliable session requirements Transaction requirements Set of predefined standard bindings. These bindings can be customized.  You can also build custom bindings.  A bindinig contains three types of binding elements.  Transport Channel Binding Element Message Encoding Binding Element Protocol Channel Binding Element WCF Bindings
Standard Bindings T = Transport Security  |  S = WS-Security | O = One-Way Only Interop Security Session Transx Duplex Stream BasicHttpBinding WsHttpBinding WsDualHttpBinding NetTcpBinding NetNamedPipeBinding NetMsmqBinding BP WS WS T TS TS TS TS TS O O NetPeerTcpBinding TS .NET .NET .NET
Defines  what  a service communicates Contract defines the interfaces what you are exposing to the outside world.  A Service Contract Group the operaitons in one service.  The signature of the operations in terms of messages exchanged.   The data types of the message. Specifies the MEP’s, The location of the operation.  Indicates categories of run-time behavior.  Also indicates sessions and Faults Maps CLR types to WSDL.  WCF Contracts
In WCF define an operation by creating method and marked with [ OperationContract]  attribute.  Even if you mark private methods with  OperationContract  attribute then it will be available to clients.  To create a service contract, group together your operations, either by declaring them within an interface or defining them within a class and marked it with [ ServiceContractAttribute ] attribute. WCF Service Contract [ ServiceContract (Namespace=&quot;http://Microsoft.ServiceModel.Samples&quot;)] public interface ICalculator  { [ OperationContract ] ComplexNumber Add(ComplexNumber n1,  ComplexNumber n2); [ OperationContract ] ComplexNumber Subtract(ComplexNumber n1,  ComplexNumber n2); void  InnerMethod(string  msg); //Not exposed to client.  }
WCF Data Contract Data Contract Defines data structures Maps CLR types to XML schema.  [ DataContract ]  attribute applied on types [ DataMember ]  attribute applied on members to be serialized.  Can be applied to private fields also.  Data Contract Example: [ DataContract ] public class ComplexNumber  { [ DataMember ] public double Real = 0.0D; [ DataMember ] public double Imaginary = 0.0D; }
Modifies or extends service or client runtime behavior  Behaviors are objects that modify the WCF runtime by either setting a runtime property or by inserting a customization type into the runtime.  Examples Instancing;  Singleton, PrivateSession, SharedSession, PerCall  Concurrency;  Multiple, Reentrant, Single  Throttling; connections, threading Metadata customization Transactions; AutoEnlist, Isolation, AutoComplete WCF Behaviors
Message Exchange Pattern One-way (Datagram) Messages send and no response. ( Datagram style delivery ) Typical for MSMQ.  Sender Receiver Request / Reply from the save Receiver Messages send another message received as a response. ( Immediate reply )  Sender Receiver Duplex Sender and receiver can exchange multiple messages. Reply later and on backchannel (callback–style).  Sender Receiver
Message Topologies Intermediary Invisible to the sender, promises to not materially change the message A received message triggers a send to another service Request / Reply from another Receiver Message sent, one or more replies from a receiver other than the original recipient Sender Receiver Intermediary Sender Receiver Sender Receiver
An  empty request  message can be described by having no input or reference parameters [OperationContract]  public int GetCurrentTemperature();   An  empty reply  message can be described by having a  void  return type and no output or reference parameters.  [OperationContract]  public void SetTemperature(int temperature);   The above operation returns an empty message. It may return a fault instead if there is a problem in processing input message.  The above is different from a  One Way  operation:  [OperationContract( IsOneWay =true)]  public void SetLightbulbStatus(bool isOn);  The above operation returns nothing. There is no way to communicate fault condition from this operation.  WCF Message Terminology
WCF is a runtime and a set of APIs for creating systems that send messages between services and clients.  WCF is based on the notion of message-based communication, and anything that can be modeled as a message.  This enables a unified API across different transport mechanisms.  In WCF model we have concept of clients and services.  Message are sent or received (or both) at endpoints.  Messages can be sent over intranets and the Internet using common transports, such as HTTP and TCP.  More transport mechanisms can be added to WCF.  WCF ships with several encoders.  Text  (TextMessageEncoder).  MTOM (MTOMMessageEncoder) Binary (BinaryMessageEncoder).  WCF Concepts
WCF Architecture: Messaging Runtime Client Dispatcher Service Contract and Behaviors Binding Address Transport Encoder Protocol(s) Transport Encoder Protocol(s)
WCF Architecture WS Security Channel Messaging HTTP Channel TCP  Channel MSMQ Channel Named Pipe Channel Transaction Flow  Channel WS Reliable  Messaging Channel Encoders (Binary/MTOM/Text/XML) Activation and Hosting Service Runtime Contracts Data Contract Message Contract Service Contract Policy  and Binding Application Windows Activation Service .EXE Windows Service COM+ Throttling Behavior Error Behavior Metadata Behavior Instance Behavior Message Behavior Transaction Behavior Dispatch Behavior Concurrency Behavior Parameter Filtering
WCF Features Summary Address Binding Behavior Contract HTTP Transport TCP Transport NamedPipe Transport MSMQ Transport Custom Transport WS-Security Protocol WS-RM Protocol WS-Coord Protocol Duplex Channel Custom Protocol http://... net.tcp://... net.pipe://... net.msmq://... xxx://... Throttling Behavior Metadata Behavior Error  Behavior Custom Behavior Instancing Behavior Concurrency Behavior Transaction Behavior Security Behavior Request/ Response One-Way Duplex net.p2p://... Peer Transport
WCF Architecture Binding Address Contract
The  WCF authentication service  enables you to use ASP.NET membership to authenticate users from any application ( Console  or  Outside of .NET  ) that can send and consume SOAP messages.  The  AuthenticationService  class contains the following methods these accessible only a through WCF service.  IsLoggedIn() Login() Logout() ValidateUser() Once authenticated the user credentials with  Login()  method, ASP.NET authentication service issues an authentication ticket as an HTTP cookie that is compatible with ASP.NET forms authentication.  Cookie-less authentication is not available through the  AuthenticationService .  In addition to methods, this AuthenticationService class also raises two events : Authenticating  and  CreatingCookie.  WCF Authentication Service Overview
Ch. Vishwa Mohan M.Sc., M.Tech Web: http://in.linkedin.com/in/vishwam Phone: +91- 9490995632   Contact Me

WCF

  • 1.
    Windows Communication FoundationCh. Vishwa Mohan M.Sc., M.Tech Freelance Software Consultant & Corporate Trainer
  • 2.
    Introducing WCF WCF Programming Life Cycle WCF Serialization Messaging Pattern WCF Bindings Hosting a WCF Service WCF Configuration Behaviors WCF Security WCF Transactions WCF Reliable Sessions WCF Queuing Agenda
  • 3.
    WCF Introduction WindowsCommunication Foundation
  • 4.
    Moving from Objectsto Services Service Oriented Architecture Concepts WCF Fundamental Concepts WS-* Standards and their relationship. WCF Architecture WCF Endpoints WCF Address, Binding and Contract WCF Introduction
  • 5.
    From Objects toServices Polymorphism Encapsulation Subclassing Message-based Schema+Contract+Policy Broad Interop Location Transparent Tight Coupling Runtime Metadata Object-Oriented Service-Oriented Component-Oriented 1980s 2000s 1990s
  • 6.
    What is aSOA ? Service-Oriented Architecture (SOA) is an approach to loosely coupled, protocol independent, standards-based distributed computing where software resources available on the network are considered as Services. SOA represents business functions as shared, reusable services. SOA is not a product but an architectural paradigm. SOA Characteristics: The software components in a SOA are services based on standard protocol. Services in SOA have minimum amount of interdependencies. Communication infrastructure used within an SOA should be designed to be independent of the underlying protocol layer. Share Schema and Contract, not Class/database Offers coarse-grained business services, as opposed to fine-grained software-oriented function calls. Uses service granularity to provide effective composition, encapsulation and management of services. A fully Implemented SOA Provides the ability to rapidly and dynamically compose applications, services and even complete processes.
  • 7.
    What is aService ? Services are reusable units providing business functionality that are… Clearly defined using standard policies, practice and framework. Clearly described (usually with XML). Autonomous Abstraction of the underlying business logic and functionality. Functionality exposed via structured messaging scheme. Not XML centric, Not HTTP centric. JSON, XML, SOAP, Images etc., over TCP, HTTP, Name Pipes, MSMQ, etc., Messages sent and received. Moves from a client/server model to a sender/receiver model. Rich communication pattern Versioning Independency. Service orientation provides the benefits of loosely coupled, message-oriented programming. Loose coupling is a requirement not a suggestion
  • 8.
    Four Tenets ofService Orientation SERVICE ORIENTATION Compatibility Based On Policy Share Schema & Contract, Not Class Services Are Autonomous Boundaries Are Explicit
  • 9.
    The Webservice technologyis stimulated (inspired) by SOA. Webservices and services are not identical. Two critical characteristics are realized for SOA development are: Services are truly independent. They can be managed. Management includes many functions including, Security, Deployment, Logging, Dynamic rerouting and Maintenance The connectivity Imperatives: Interoperability and Integration. Secure, Reliable and Transacted Messages. Decoupled Dynamic Applications. WCF will be the foundation for service oriented applications built on top of the .NET framework. Service Oriented Architecture (SOA)
  • 10.
    SOA Implementation inWCF Boundaries are Explicit Services are autonomous Share schema & contract, not class Compatibility based on policy Developers opt-in to consuming, exposing, and defining public-facing service façade. Services and consumers are independently versioned, deployed, operated, and secured . Data never includes behavior; Objects with data and behavior are a local phenomenon. Capabilities and requirements represented by a unique public name; Used to establish service suitability.
  • 11.
    Anatomy of aService ? A service use a channel to communicate. Through channel messages are sent and received. The messages are build according to predefined contract with data according to predefined schema. Service can use Policies indicating what and how the client should behave.
  • 12.
    How to buildService Oriented Applications? “ What API should I use?” “ How do I build service-oriented systems?” “ How can I send messages securely & reliably?” “ How do I build dynamic, decoupled applications?”
  • 13.
    An API forcommunicating between applications and services. Provides secure , reliable , and transacted messaging along with interoperability. Unifies a broad array of distributed systems capabilities in an extensible architecture. Spans transports , security systems, messaging patterns, encodings , network topologies, and hosting models. WCF combines the best of all existing Microsoft distributed computing stacks. WCF uses WS-* standards for interoperability and .NET value-add for performance and integration with existing solutions WCF is the future of distributed computing. What is WCF ?
  • 14.
    Extending the .NETFramework WCF Presentation Data Communication Windows Forms ASP.NET SQL Server Compact Framework Console & NT Service … J# C++ C# VB Base App Services Security Configuration Deployment & Management Visual Studio 2008
  • 15.
    Windows Communication FoundationINTEROPERABILITY PRODUCTIVITY SERVICE-ORIENTED DEVELOPMENT Broad Support for WS-* specifications Compatible with existing MS distributed application technologies Unifies today’s distributed technologies Attribute-based development Visual Studio Integration Enables development of loosely-coupled services Config-based communication
  • 16.
    WCF Unified ProgrammingModel ( Supersets Existing Technologies ) Interop with other platforms ASMX Attribute- Based Programming Enterprise Services WS-* Protocol Support WSE 2/3 Message- Oriented Programming MSMQ Extensibility Location transparency .NET Remoting Supersets Existing Technologies
  • 17.
    WCF address rangeof challenges for communicating applications: Unification of existing .NET Framework Communication technologies. Support for cross-vendor interoperability. Explicit Service Orientation. WCF address the following unified distributed technologies: Web Services (ASPX) .NET Remoting WSE Enterprise Services MSMQ WCF supports large set of WS-* specifications. So it provides reliability, security, and transactions when communicating with any platform that also supports these specifications. With WCF also achieve high performance with binary encoding. Unified Programming Model
  • 18.
    WS-* Protocol SupportSecurity WS-Security WS-Trust WS-Secure Conversation Messaging SOAP, WS-Addressing, MTOM Reliability WS-Reliable Messaging Transactions WS-Atomic Transactions WS-Coordination Metadata WSDL, WS-Policy WS-MetadataExchange WCF supports all the specifications shown in the below fig: XML
  • 19.
    Distributed computing/communications platformsneed to interoperate with the technologies different vendors offer. Likewise, security must also be interoperable . To enable interoperable security systems a few notable standards have been proposed by Webservice industry. WS-Security WS-Trust WS-SecureConversation WS-SecurityPolicy All the above standards defines addition to SOAP messages for providing authentication, data integrity and data piracy. WCF also provides support for Kerberos, NTLM, Username, Certificates supported as credential tokens. SAML Claims support. WCF Security
  • 20.
    Support for WS-AtomicTransaction and WS-Coordination . Provides distributed transaction enlistment with commit / rollback. Automatic flow provided by transaction scope. Allows using two-phase commit transaction with SOAP based message exchanges. WCF Transaction
  • 21.
    Reliable messaging ishow a reliable messaging source transfers messages reliably to a reliable messaging destination. Supports WS-ReliableMessaging . It defines addition to the SOAP header that allows reliable end to end communication. Provides mechanism to guarantee delivery via acknowledgement protocol. Note: Retries can be very slow. WCF Reliability
  • 22.
    WS-* Composability andMessage Anatomy
  • 23.
    Investment Protection SIDE-BY-SIDEInterop UPGRADE Side-by-side co-existence with existing distributed technologies. Smooth upgrade of existing code to WCF Seamless communications with application built on existing technologies
  • 24.
    WCF is Microsoft’sunified programming model for building service-oriented applications.  WCF enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments. WCF is implemented primarily as a set of classes on top of .NET Framework CLR. WCF’s fundamental communication mechanism is SOAP-based WebServices. WCF Introduction Caller Service Service 1 Service 2 Message Message All messages are SOAP based
  • 25.
    SOAP is XMLbased protocol providing message construct. Presently 2 SOAP versions are in use. SOAP 1.1 is built on XML SOAP 1.2 is built on XML Infoset. A SOAP message is composed of: An Envelop. Within an envelop optional header section and mandatory body. Within a header zero or more header blocks. What is SOAP ? <S:Envelope> <S:Header> <n:HeaderBlock> . . . </n:HeaderBlock> </S:Header> <S:Body> . . . </S:Body> </S:Envelope>
  • 26.
    Example of SimpleSOAP Envelope <?xml version=&quot;1.0&quot;?> < soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> < soap:Heade r> <m:Trans xmlns:m=&quot;http://www.w3schools.com/transaction/&quot; soap:mustUnderstand=&quot;1&quot;>234</m:Trans> </ soap:Header > < soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </ soap:Body > </ soap:Envelope >
  • 27.
    A service isa construct that exposes one or more endpoints, each of which exposes one or more service operations. Endpoints are defined for communication between services. The endpoint of a service specifies: An address where the service can be found. It is basically a URI. A binding that specifies how a client communicate with the endpoint. Finally a contract that defines the functionality provided by the service to its clients. End Points Caller Service Message Endpoint Endpoint Endpoint
  • 28.
    A endpoint cansend and receive messages independent of transport . The endpoint of a service can be specified either imperatively through code or declaratively through configuration file. The endpoint represented in WCF object model by ServiceEndpoint class. Each endpoint is made up of three elements: Address: It is a basically URI. In WCF object model this address is represented by EndpointAddress . Binding: It describes how a service communicate with the partners. So it consists of collection of details such as transport method, encoding, reliability requirements, and security considerations. Represented by Binding class. WCF Creates channel stack to satisfy the using binding. Contract: It consists of collection of operations that endpoint expose to the outside world. Represented by ContractDescription class. End Points
  • 29.
    Address, Binding andContract Caller Service Message Address Binding Contract (Where) (How) (What) There are two ways to specify endpoint address for a service in WCF. You can specify an absolute address for each endpoint associated with service. You can provide a base address for the ServiceHost of a service and specify an address for each endpoint relative to this base address. A B C A B C A B C
  • 30.
    Defines where a service is located. Specifies a URI where the service is located. Relative or Absolute The Address of endpoint represented in WCF by EndpointAddress class. It consists basically URI , an Identity and collection of optional Headers . Address consists of: Scheme ( HTTP, TCP, Named Pipes, MSMQ) Machine (www.visitech.com) [Port] : (optional 1024) Path: MbusOpcServer.svc/secureEP Examples: http://ww.visitech.com:1024/MbusOpcServer.svc net.tcp://visitech.com:1024/MbusOpcServer.svc WCF Address
  • 31.
    Describes how a service communicates Specifies set of binding elements Transport; http, tcp, np, msmq Encoding format; text, binary, MTOM, ... Security requirements Reliable session requirements Transaction requirements Set of predefined standard bindings. These bindings can be customized. You can also build custom bindings. A bindinig contains three types of binding elements. Transport Channel Binding Element Message Encoding Binding Element Protocol Channel Binding Element WCF Bindings
  • 32.
    Standard Bindings T= Transport Security | S = WS-Security | O = One-Way Only Interop Security Session Transx Duplex Stream BasicHttpBinding WsHttpBinding WsDualHttpBinding NetTcpBinding NetNamedPipeBinding NetMsmqBinding BP WS WS T TS TS TS TS TS O O NetPeerTcpBinding TS .NET .NET .NET
  • 33.
    Defines what a service communicates Contract defines the interfaces what you are exposing to the outside world. A Service Contract Group the operaitons in one service. The signature of the operations in terms of messages exchanged. The data types of the message. Specifies the MEP’s, The location of the operation. Indicates categories of run-time behavior. Also indicates sessions and Faults Maps CLR types to WSDL. WCF Contracts
  • 34.
    In WCF definean operation by creating method and marked with [ OperationContract] attribute. Even if you mark private methods with OperationContract attribute then it will be available to clients. To create a service contract, group together your operations, either by declaring them within an interface or defining them within a class and marked it with [ ServiceContractAttribute ] attribute. WCF Service Contract [ ServiceContract (Namespace=&quot;http://Microsoft.ServiceModel.Samples&quot;)] public interface ICalculator { [ OperationContract ] ComplexNumber Add(ComplexNumber n1, ComplexNumber n2); [ OperationContract ] ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2); void InnerMethod(string msg); //Not exposed to client. }
  • 35.
    WCF Data ContractData Contract Defines data structures Maps CLR types to XML schema. [ DataContract ] attribute applied on types [ DataMember ] attribute applied on members to be serialized. Can be applied to private fields also. Data Contract Example: [ DataContract ] public class ComplexNumber { [ DataMember ] public double Real = 0.0D; [ DataMember ] public double Imaginary = 0.0D; }
  • 36.
    Modifies or extendsservice or client runtime behavior Behaviors are objects that modify the WCF runtime by either setting a runtime property or by inserting a customization type into the runtime. Examples Instancing; Singleton, PrivateSession, SharedSession, PerCall Concurrency; Multiple, Reentrant, Single Throttling; connections, threading Metadata customization Transactions; AutoEnlist, Isolation, AutoComplete WCF Behaviors
  • 37.
    Message Exchange PatternOne-way (Datagram) Messages send and no response. ( Datagram style delivery ) Typical for MSMQ. Sender Receiver Request / Reply from the save Receiver Messages send another message received as a response. ( Immediate reply ) Sender Receiver Duplex Sender and receiver can exchange multiple messages. Reply later and on backchannel (callback–style). Sender Receiver
  • 38.
    Message Topologies IntermediaryInvisible to the sender, promises to not materially change the message A received message triggers a send to another service Request / Reply from another Receiver Message sent, one or more replies from a receiver other than the original recipient Sender Receiver Intermediary Sender Receiver Sender Receiver
  • 39.
    An emptyrequest message can be described by having no input or reference parameters [OperationContract] public int GetCurrentTemperature(); An empty reply message can be described by having a void return type and no output or reference parameters. [OperationContract] public void SetTemperature(int temperature); The above operation returns an empty message. It may return a fault instead if there is a problem in processing input message. The above is different from a One Way operation: [OperationContract( IsOneWay =true)] public void SetLightbulbStatus(bool isOn); The above operation returns nothing. There is no way to communicate fault condition from this operation. WCF Message Terminology
  • 40.
    WCF is aruntime and a set of APIs for creating systems that send messages between services and clients. WCF is based on the notion of message-based communication, and anything that can be modeled as a message. This enables a unified API across different transport mechanisms. In WCF model we have concept of clients and services. Message are sent or received (or both) at endpoints. Messages can be sent over intranets and the Internet using common transports, such as HTTP and TCP. More transport mechanisms can be added to WCF. WCF ships with several encoders. Text (TextMessageEncoder). MTOM (MTOMMessageEncoder) Binary (BinaryMessageEncoder). WCF Concepts
  • 41.
    WCF Architecture: MessagingRuntime Client Dispatcher Service Contract and Behaviors Binding Address Transport Encoder Protocol(s) Transport Encoder Protocol(s)
  • 42.
    WCF Architecture WSSecurity Channel Messaging HTTP Channel TCP Channel MSMQ Channel Named Pipe Channel Transaction Flow Channel WS Reliable Messaging Channel Encoders (Binary/MTOM/Text/XML) Activation and Hosting Service Runtime Contracts Data Contract Message Contract Service Contract Policy and Binding Application Windows Activation Service .EXE Windows Service COM+ Throttling Behavior Error Behavior Metadata Behavior Instance Behavior Message Behavior Transaction Behavior Dispatch Behavior Concurrency Behavior Parameter Filtering
  • 43.
    WCF Features SummaryAddress Binding Behavior Contract HTTP Transport TCP Transport NamedPipe Transport MSMQ Transport Custom Transport WS-Security Protocol WS-RM Protocol WS-Coord Protocol Duplex Channel Custom Protocol http://... net.tcp://... net.pipe://... net.msmq://... xxx://... Throttling Behavior Metadata Behavior Error Behavior Custom Behavior Instancing Behavior Concurrency Behavior Transaction Behavior Security Behavior Request/ Response One-Way Duplex net.p2p://... Peer Transport
  • 44.
    WCF Architecture BindingAddress Contract
  • 45.
    The WCFauthentication service enables you to use ASP.NET membership to authenticate users from any application ( Console or Outside of .NET ) that can send and consume SOAP messages. The AuthenticationService class contains the following methods these accessible only a through WCF service. IsLoggedIn() Login() Logout() ValidateUser() Once authenticated the user credentials with Login() method, ASP.NET authentication service issues an authentication ticket as an HTTP cookie that is compatible with ASP.NET forms authentication. Cookie-less authentication is not available through the AuthenticationService . In addition to methods, this AuthenticationService class also raises two events : Authenticating and CreatingCookie. WCF Authentication Service Overview
  • 46.
    Ch. Vishwa MohanM.Sc., M.Tech Web: http://in.linkedin.com/in/vishwam Phone: +91- 9490995632 Contact Me