WCF

Views:
 
Category: Education
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

WCF : 

WCF WCF Fundaments End Points Binding and Behavior Contracts and Service host Message and Channel WCF client and Meta data

Slide 2: 

End Points Address : specifies where this WCF service is (where) hosted. Contract : Collection of operation that specifies what (what) the endpoint will communicate with outside world. Binding : describes how client will communicate with service. (How) Ex: <endpoint Address =http://localhost:8090/MyService/MathService.svc" contract = "IMathService" Binding = "wsHttpBinding"/>

2. Binding and Behavior Same Service can be using deferent users with deferent formats.Suppose one client will be access SOAP using Http and another client will be access same service with binary using TCP protocol. Ex: SOAP using Http Protocol <endpoint address="http://localhost:8090/MyService/MathService.svc" contract="IMathService" binding="wsHttpBinding"/> Binary format using TCP Protocal<endpoint address="net.Tcp://localhost:8080/MyService/MathService.svc" contract="IMathService" binding="netTcpBinding"/> : 

2. Binding and Behavior Same Service can be using deferent users with deferent formats.Suppose one client will be access SOAP using Http and another client will be access same service with binary using TCP protocol. Ex: SOAP using Http Protocol <endpoint address="http://localhost:8090/MyService/MathService.svc" contract="IMathService" binding="wsHttpBinding"/> Binary format using TCP Protocal<endpoint address="net.Tcp://localhost:8080/MyService/MathService.svc" contract="IMathService" binding="netTcpBinding"/>

Slide 4: 

3. Contracts and Service host Contracts Service Contract: Describe the operation that service can provide. Data Contract : Describes the custom data type which is exposed to the client. Message Contract: Default SOAP message format is provided by the WCF runtime for communication between Client and service. 4. Fault Contract: Documented view for error occurred in the service to client.

Slide 5: 

Service Host Service Host object is in the process of hosting the WCF service and registering endpoints. It loads the service configuration endpoints, apply the settings and start the listeners to handle the incoming request. System.ServiceModel.ServiceHost namespace hold this object. This object is created while self hosting the WCF service. In the below example you can find that WCF service is self hosted using console application. //Creating uri for the hosting the service Uri uri = new Uri("http://localhost/CategoryService");//Creating the host object for MathService ServiceHost host = new ServiceHost(typeof(CategoryService), uri);//Adding endpoint to the Host object host.AddServiceEndpoint(typeof(ICategoryService),new WSHttpBinding(), uri); host.Open(); //Hosting the Service Console.WriteLine("Waiting for client invocations"); Console.ReadLine(); host.Close();

Slide 6: 

4. Messages and Channel  Message WCF Message is the unit of data exchange between client and service. It consists of several parts, including a body and headers. WCF Runtime WCF runtime is the set of object responsible for sending and receiving message. For example formatting the message, applying security and transmitting and receiving message using various protocols. Channels: Channels are the core abstraction for sending message to and receiving message from an Endpoint. Broadly we can categories channels as Transport Channels - Handles sending and receiving message from network. Protocols like HTTP, TCP name pipes and MSMQ. Protocol Channels - Implements SOAP based protocol by processing and possibly modifying message. e.g. WS-Security and WS-Reliability.

Slide 7: 

5. WCF Client WCF client is a client application creates to expose the service operations as method. Any application can host a WCF client, including an application that host a service. Therefore it is possible to create a service that includes WCF clients of other services. A client application is a managed application that uses a WCF client to communicate with another application. To create a client application for a WCF 1. service requires the following steps: Get the Proxy class and service end point information Using SvcUtil.exe we can create proxy class for the service and configuration information for endpoints. Example type the following sentence in the Visual studio command prompt, this will generate the class file and configuration file which contain information about the endpoints .

Slide 8: 

svcutil /language:vb /out:ClientCode.vb /config:app.config http://localhost:8090/MyService/SimpleCalculator.svc?wsd 2. Call operations. Add this class files in the client application. Then create the object for this class and invoke the service operation. Configuration information we got from the above step has to be added to the client application configuration file. When the client application calls the first operation, WCF automatically opens the underlying channel. This underlying channel is closed, when the object is recycled. //Creating the proxy on client sideMyCalculatorServiceProxy.MyServiceProxy proxy = new MyCalculatorServiceProxy.MyServiceProxy(); Console.WriteLine("Counter: " + proxy.MyMethod()); 3. Close the WCF client object. After using the object created in the above steps, we have to dispose the object. Channel will be closed with the service, when the object is cleared.

Slide 9: 

Metadata Characteristics of the service are described by the metadata. This metadata can be exposed to the client to understand the communication with service. Metadata can be set in the service by enabling the ServiceMetadata node inside the servcieBehaviour node of the service configuration file. <system.serviceModel> <services> <service name="MathService" behaviorConfiguration="MathServiceBehavior"> <endpoint address="" contract="IMathService" binding="wsHttpBinding"/> </service> </services>

PICTURE ABHI BHAKHI HAI MERE BHAI : 

PICTURE ABHI BHAKHI HAI MERE BHAI