1 / 21

Introduction to Windows Communication Foundation

Introduction to Windows Communication Foundation. Ruwan Wijesinghe. Provide a unified communication model for all windows based distributed application development technologies ( ASMX web services , .Net Remoting , Enterprise Services , MSMQ )

Download Presentation

Introduction to Windows Communication Foundation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction toWindows Communication Foundation Ruwan Wijesinghe

  2. Provide a unified communication model for all windows based distributed application development technologies (ASMX web services, .Net Remoting, Enterprise Services, MSMQ) Fully Support WS-I and hence interoperable with applications developed in other platforms Support transport mediums like TCP – Efficient intranet communication HTTP – For communication over the fire walls (Internet) Named Pipes – For efficient inter process communication MSMQ – Reliable messaging Support three messaging patterns Simplex – Send a message and do not expect a reply Duplex – Send a message with a callback interface. Service can replies asynchronously using this callback interface, if required. Request Reply – Send a message and expect a reply Windows Communication Foundation

  3. Internet Information Server (IIS) – Supports, clustering, domain recycling, etc. IIS 6 supports only HTTP IIS7 (WAS) supports any communication protocol Windows Executables – Windows and Console applications can host services as s means of inter-process communication Windows Services – Windows services can be used to host WCF services. This can be used as a means of inter-process communication as well as for distributed application development Hosting Services

  4. ServiceEndpoints contain the ABCs of a service. EndpointAddress (A): A WCF service endpoint has a URI. EndpointAddress contains the URI, optional Address Headers and an optional Identity field (only useful when having multiple end points that shares the same URI) Binding (B): Bindings are a portion of the Policy that a service and consumer have to agree on if they want to exchange messages. This binding will contain the information to support the features being exposed by the service. ContractDescription (C): There are a number of different types of contracts with WCF. The primary contract that defines service is the service contract. This is analogous to the portType within WSDL today. Service Endpoint

  5. Binding contains following information Name – Name of the binding Namespace – The namespace that makes the binding name unique BindingElements – A list of binding elements that defines different aspects of the expected binding Binding

  6. Bindings are capable of answering a number of questions about how a client and a service will communicate. Here are the key questions that are answered. What level of interoperability does this service have? .NET to .NET or WS* specifications. What type of encoding is used? Text, MTOM or Binary What type of transports can be used? TCP, HTTP, Named Pipe, or MSMQ. What type of messaging patterns can be used? Simplex, duplex, or request-reply. What type of security is supported? Windows security, WS-Security, or transport level security. Is transaction flow supported? Are reliable sessions supported? Exactly what does the binding tell us?

  7. A binding is a set of Binding Elements Types of Binding Elements Transport Bindings – Binding which determines the transport type (e.g. TCP, HTTP, MSMQ, etc.) Protocol Binding – The binding which process SOAP headers and implement protocols like (WS-Security, etc.) Example Bindings Security Binding Element ReliableSession Binding Element TcpTransport Binding Element Binding Elements

  8. ContractDescription contains the following parts Name – Name of the service Namespace – The namespace that makes the service name unique OperationDescription – Descriptions of the operations (methods) of the service Message Description – Descriptions of the input and output messages of the service ContractBehavior – ContractBehaviors modifies or extend the behavior of the service contract Contract Description

  9. Services are described using ServiceDescriptions ServiceDescripion contsins ServiceType – The type that provide the service IServiceBehavior – The modifications or extensions to the service E.g. ServiceMetadataBehavior determines if the service publishes its metadata ServiceEndpoint – A set of ServiceEndpoints as discussed in previous slides (EndpointAddress, Binding and Contract) Service Description

  10. Channels are used by clients to communicate with services There are two types of channels Transport Channels – Channels used to support transport mediums like TCP Protocol Channels – Channles used to support SOAP based protocols like WS-Security Generally a set of channels are used to access a given service endpoint Channels are described by ChannelDescriptions which contains, IChannelBehavior – Set of modifications or extensions to the channel behavior ServiceEndpoint – Service endpoints as discussed earlier Channels

  11. A configuration file entry of a service hosted in IIS or WAS is given below Service Configuration <configuration> <system.serviceModel> <services> <servicetype="ServiceLibrary.EchoService"> <endpointaddress="svc" binding="basicHttpBinding" contract="ServiceLibrary.IEchoService"/> <endpointaddress="net.tcp://localhost:8081/echo/svc" binding="netTcpBinding" contract="ServiceLibrary.IEchoService"/> </service> </services> </system.serviceModel> </configuration>

  12. Predefined Bindings .

  13. Single – Use a single instance to serve all the requests PerSession – New instance will be created per session PerCall – New instance will be created per request (method call) Shared – Instances will be pooled and shared Instance Modes

  14. [ServiceContract(Name="EventsService)] public interfaceIEventsService { [OperationContract(Name = "SaveEvent")] void SaveEvent(LinkItem item); [OperationContract(Name = "GetEvent")] LinkItem GetEvent(); } Service Interface

  15. public classEventsService: IEventsService { privateLinkItem m_linkItem; public void SaveEvent(LinkItem item) { m_linkItem = item; } publicLinkItem GetEvent() { return m_linkItem; } } Implementing Interface

  16. [DataContract(Name="LinkItem")] public class LinkItem { [DataMember(Name="Id", IsRequired=false, Order=0)] private long m_id; [DataMember(Name = "Title", IsRequired = true, Order = 1)] private string m_title; [DataMember(Name="Desc", IsRequired = false, Order = 2)] private string m_desc; public long Id { get { return m_id; } set { m_id = value; } } public string Title { get { return m_title; } set { m_title = value; } } public string Description { get { return m_description; } set { m_description = value; } } } Data Contracts

  17. [MessageContract] public classSaveEventRequest { private string m_licenseKey; privateLinkItem m_linkItem; [MessageHeader(MustUnderstand=true)] public string LicenseKey { get { return m_licenseKey; } set { m_licenseKey = value; } } [MessageBody(Order=0)] publicLinkItem LinkItem { get { return m_linkItem; } set { m_linkItem = value; } } } Message Contracts

  18. [ServiceContract(Name="EventsService")] public interfaceIEventsService { [OperationContract(Name = "SaveEvent")] SaveEventResponse SaveEvent(SaveEventRequest message); [OperationContract(Name = "GetEvent")] GetEventResponse GetEvent(GetEventRequest message); } Service Interface with Messages

  19. Services can be hosted in any executable These services can be configured Directly by code Using a configuration file (recommended) Configuring using code ServiceHost sh = new ServiceHost(typeof(MathService)); sh.AddServiceEndpoint( typeof(IMath), //contract type new WSHttpBinding(), //one of the built-in bindings"http://localhost/MathService/Ep1"//the endpoint's address); sh.Open(); //create and open the service runtime Hosting a Service in an Executable

  20. WCF can be written by using two techniques Direct Code ChannelFactory<IMath> factory = new ChannelFactory<IMath>( new WSHttpBinding(), new EndpointAddress("http://localhost/MathService/Ep1")); IMath channel = factory.CreateChannel(); int result = channel.Add(35,7); factory.Close(); Using Proxy MathProxy proxy = new MathProxy(); int result = proxy.Add(35, 7); WCF Clients

  21. WCF can be configured to log its incoming and outgoing messages SvcTraceViewer tools can be used to analyze this data Loggin Messages

More Related