Search This Blog

Friday, February 12, 2016

ABCs of an EndPoint in WCF

This article is targeted to beginners in WCF. This is a totally theoretical article. It will explain:
  1. All the theoretical concepts of an EndPoint in WCF.
  2. Addresses in WCF
  3. Binding and where, which binding should be used.
  4. Contracts.
ABCs of Endpoints in WCF

The three elements of an endpoint starts with letters that make a mnemonic phrase.

"ABCs of Endpoints"

image1.gif


image2.gif
image3.gif

Address of an Endpoint(A)

image4.gif
  1. A address specifes where the service is residing.
  2. This is a Uniform Resource Locator (URL).
  3. The address URL identifies the location of the service.
  4. The address should folllow the "Web Service Addressing" (WS-Addressing) standard.

    image5.gif

    image6.gif
The address depends on whether it is hosted in IIS or a managed application or WAS. This also depends on the binding being used.

The following are example of various types of addresses:

image7.gif

Binding of an Endpoint (B)

The Binding is how the service is to be used. The Binding specifies:
  1. Which protocol to use.
  2. Which encoding to use.
  3. What type of security requeiremnets are to be used, like SSL or SOAP message security.
System provided Bindings
The system-provided Bindings are basicHttpBinding, wsHttpBinding, wsDualHttpBinding, webHttpBinding, wsFederationHttpBinding, netTCPBinding, netNamedPipeBinding, netMSMQBinding, netPeerTCPBinding, msmqIntegrationBinding, basicHttpContextBinding, netTCPContextBinding and wsHttpContextBinding.

The following describes basicHttpBinding:
  1. This is interoperable binding.
  2. This is commonly used as a replacement for earler web services based on ASMX.
  3. It supports HTTP & HTTPS protocols.
  4. It supports MTOM encoding.
  5. It supports text encoding.
The following describes wsHttpBinding:
  1. This is a secure binding.
  2. This is interoperable binding.
  3. This uses SOAP over HTTP.
  4. This supports reliability over internet.
  5. This supports transaction over internet.
  6. This supports security over internet.
  7. This supports HTTP/HTTPS proptcol
  8. This supports text and MTOM encoding.
  9. This is default binding provided by WCF.
The following describes wsDualHttpBinding:
  1. This supports all the features of wsHttpBinding.
  2. This is mainly used for DUPLEX SERVICE CONTRACTS.
  3. This supports bidirectional communication.
The following describes webHttpBinding:
  1. This is a secure binding.
  2. This is a interoperable binding.
  3. It supports Http/Https protocol.
  4. It does not use SOAP message format. 

    image8.gif
The following describes wsFederationHttpBinding:
  1. This is a secure Binding.
  2. This is interoperable binding.
  3. This supports federated security
  4. This supports Https/Https protocols.
  5. This uses text/MTOM encoding.

    image9.gif
The following describes netTCPBinding:
  1. This is a secure Binding.
  2. This could only be used if the client is also a WCF machine.
  3. This is used to send Binary encoded SOAP messages from one WCF computer to another.
  4. This uses Transimission Control Protocol (TCP).
  5. This supports reliability.
  6. This supports transaction.
  7. This supports security.
The following describes netNamedPipeBinding:
  1. This is a secure Binding.
  2. This could be used over a single WCF computer.
  3. This sends Binary encoded SOAP message over named pipes.
The following describes netMSMQBinding:
  1. This is a queued Binding.
  2. This uses Binary encoded SOAP message.
  3. This sends message over MSMQ.
  4. Here the communication should occur between two computers.
The following describes netPeerTCPBinding:
  1. This is a secure Binding.
  2. This uses TCP over peer to peer.
  3. The Communication should occur between two or more computers.
The following describes msmqIntegrationBinding:

image10.gif

basicHttpContextBinding
This Binding is the same as basicHttpBinding except with more attributes, as in the following:
  1. It supports HTTP cookies
  2. It eanbles SOAP haeders to exchange context.
  3. This binding is mainly used for Durable services.
netTCPContextBinding
This Binding is the same as netTCPBinding except with more attributes, as in the following
  1. It eanble SOAP haeders to excahnge context.
  2. This binding is mainly used for Durable services.
wsHttpContextBinding
This Binding is the same as wsHttpBinding with more attributes, as in the following:
  1. It eanble SOAP haeders to excahnge context.
  2. This binding is mainly used for Durable services.
Example :
<system.serviceModel>
                   <
services>
                             <
service name="WcfService2.Service1"behaviorConfiguration="WcfService2.Service1Behavior">                                      <!-- Service Endpoints -->
<endpoint  address="" binding="wsHttpBinding" contract="WcfService2.IService1">                                                <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          
-->
                                                <
identity>
                                                          <
dns value="localhost"/>                                                </identity>
                                      </
endpoint>
                                      <
endpoint address="mex" binding="mexHttpBinding"contract="IMetadataExchange"/>                             </service>
                   </
services>
                   <
behaviors>
                             <
serviceBehaviors>
                                      <
behavior name="WcfService2.Service1Behavior">                                                <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                                                <
serviceMetadata httpGetEnabled="true"/>                                                <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                                                <
serviceDebug includeExceptionDetailInFaults="false"/>                                      </behavior>
                             </
serviceBehaviors>
                   </
behaviors>          </system.serviceModel>
Contract of and EndPoint (C)

image12.gif
  1. The contract should be an Interface
  2. The contract could be a class also but the better approach is interface.
  3. In the config file this is preceded by prpject name space name
<endpoint  address="" binding="wsHttpBinding" contract="WcfService2.IService
                                       
            
                                                                               OR


EndPoint

WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for communicating with the world.
All the WCF communications are take place through end point. End point consists of three components.

Address

Basically URL, specifies where this WCF service is hosted .Client will use this url to connect to the service. e.g
http://localhost:8090/MyService/SimpleCalculator.svc

Binding

Binding will describes how client will communicate with service. There are different protocols available for the WCF to communicate to the Client. You can mention the protocol type based on your requirements.
A binding has several characteristics, including the following:
  • Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are some type of protocols.
  • Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format that allows the effective transmission of attachments or large messages (greater than 64K).
  • Protocol(Optional) - Defines information to be used in the binding such as Security, transaction or reliable messaging capability
The following table gives some list of protocols supported by WCF binding.
BindingDescription
BasicHttpBindingBasic Web service communication. No security by default
WSHttpBindingWeb services with WS-* support. Supports transactions
WSDualHttpBindingWeb services with duplex contract and transaction support
WSFederationHttpBindingWeb services with federated security. Supports transactions
MsmqIntegrationBindingCommunication directly with MSMQ applications. Supports transactions
NetMsmqBindingCommunication between WCF applications by using queuing. Supports transactions
NetNamedPipeBindingCommunication between WCF applications on same computer. Supports duplex contracts and transactions
NetPeerTcpBindingCommunication between computers across peer-to-peer services. Supports duplex contracts
NetTcpBindingCommunication between WCF applications across computers. Supports duplex contracts and transactions

Contract

Collection of operation that specifies what the endpoint will communicate with outside world. Usually name of the Interface will be mentioned in the Contract, so the client application will be aware of the operations which are exposed to the client. Each operation is a simple exchange pattern such as one-way, duplex and request/reply.
Below figure illustrate the functions of Endpoint

Example:

Endpoints will be mentioned in the web.config file on the created service.
<system.serviceModel>
<services>
      <service name="MathService"
        behaviorConfiguration="MathServiceBehavior">
       <endpoint
         address="http://localhost:8090/MyService/MathService.svc" contract="IMathService"
          binding="wsHttpBinding"/> 
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MathServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  




No comments:

Post a Comment