Mohammed Atef’s Technical blog

Select WCF Binding

While I was reading this book Addison.Wesley.Essential.Windows.Communication.Foundation, I read very useful and important topic about WCF selects binding. so I would like to share this nice information to all.

Introduction

Actually there are nine preconfigured bindings in WCF, Each of these provides the means for a particular distributed computing need, there are several factors that  determine which binding to choose for a specific application, including security, interoperability, reliability, performance, and transaction requirements. You can study these cases throw the below image.
 wcfbinding
Each of the bindings supports a particular communication scenario, such as cross- machine, on-machine, and interoperable communication using Web services; I will explain each communication scenario in details with very simple example.

netTcpBinding

 The netTcpBinding binding is designed to support communication between .NET applications that are deployed on separate machines across a network, including communication across intranets and the Internet. This type of communication called cross-machine communication.
Address format: net.tcp://{hostname}[:port]/{service location}
Default port number:808

netTcpBinding Service Configuration

<services>
<service name="EssentialWCF.Service1" behaviorConfiguration="EssentialWCF.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost/EssentialWCF"/>
          </baseAddresses>
        </host>
<endpoint address="" binding="netTcpBinding" contract="EssentialWCF.IService1"></endpoint>
</service>
</services>

netTcpBinding Client Configuration

<client>
<endpoint address="net.tcp://localhost/Service1.svc" binding="netTcpBinding" contract="ServiceReference1.IService1"></endpoint>
</client>

netNamedPipeBinding

 WCF supports interprocess and intraprocess communication scenarios with the netNamedPipeBinding binding.the netNamedPipeBinding binding leverages a named pipes transport. This is a great binding to use for doing interprocess communication (IPC) because it provides a significant performance increase over the other standard bindings available in WCF.
This type of communication called Local machine communication.
Address format: net.pipe://{hostname}/{service location}
Default port number:808

 

 

netNamedPipeBinding Service Configuration
<services>
<service name="EssentialWCF.Service1" behaviorConfiguration="EssentialWCF.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="net.pipe://localhost/EssentialWCF"/>
          </baseAddresses>
        </host>
<endpoint address="" binding="netNamedPipeBinding" contract="EssentialWCF.IService1"></endpoint>
</service>
</services>
netNamedPipeBinding Client Configuration

basicHttpBinding

<client>
<endpoint address="net.pipe://localhost/Service1.svc" binding="netNamedPipeBinding" contract="ServiceReference1.IService1"></endpoint>
</client>

 

The basicHttpBinding binding offers support for Web service communication based on the WS-I Basic Profile 1.1 (WS-BP 1.1) specification. This includes standards such as SOAP 1.1, WSDL 1.1, and Message Security 1.0. This type of communication called web service communication.

Address format: http://{hostname}/{service location} and https://{hostname}/{service location}
Default port number:80 for http and 443 for https

basicHttpBinding Service Configuration

basicHttpBinding Client Configuration

<client>
<endpoint address="http://localhost/Service1.svc" binding=" basicHttpBinding " contract="ServiceReference1.IService1"></endpoint>
</client>

wsHttpBinding

The wsHttpBinding binding provides interoperable communication across heterogeneous platforms as well as advanced infrastructure level protocols, such as security, reliable messaging, and transactions. The wsHttpBinding binding is the default binding in .NET Framework 3.0 whenever you need interoperable communication based on Web services. This type of communication called Advanced web service communication.

Address format: http://{hostname}:{port}/{service location} and https://{hostname}:{port}/{service location}Default port number:80 for http and 443 for https

wsHttpBinding Service Configuration

wsHttpBinding Client Configuration

<client>
<endpoint address="http://localhost/Service1.svc" binding=" wsHttpBinding " contract="ServiceReference1.IService1"></endpoint>
</client>

ws2007HttpBinding

.NET Framework 3.5 introduces a new binding for Web service interoperability called the ws2007HttpBinding binding. This binding is similar to the

ws2007HttpBinding binding except that it supports the latest WS-* standards available for messaging, security, reliable messaging, and transactions.This type of communication called Advanced web service communication.

Address format: http://{hostname}:{port}/{service location} and https://{hostname}:{port}/{service location}Default port number:80 for http and 443 for https

ws2007HttpBinding Service Configuration

ws2007HttpBinding Client Configuration

<client>
<endpoint address="http://localhost/Service1.svc" binding=" ws2007HttpBinding " contract="ServiceReference1.IService1"></endpoint>
</client>

wsDualHttpBinding

The wsDualHttpBinding binding is similar to the wsHttpBinding binding, with additional support for duplex communication and lack of support for transport-level security. This type of communication called Advanced web service communication.

Address format: http://{hostname}:{port}/{service location}
Default port number:80 for http

wsDualHttpBinding Service Configuration

<services>
<service name="EssentialWCF.Service1" behaviorConfiguration="EssentialWCF.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/EssentialWCF"/>
          </baseAddresses>
        </host>
<endpoint address="" binding="wsDualHttpBinding" contract="EssentialWCF.IService1"></endpoint>
</service>
</services>

wsDualHttpBinding Client Configuration

<client>
<endpoint address="http://localhost/Service1.svc" binding="wsDualHttpBinding" contract="ServiceReference1.IService1"></endpoint>
</client>

Now I think we can decide with WCF binding type we can use in our solutions.

I hope this help.

June 9, 2009 Posted by | WCF | , , , , , , | 1 Comment

WCF Binding:BasicHttpBinding vs WsHttpBinding

Introduction

The first thing developers starting to implement Windows Communication Foundation (WCF) should know the difference between the BasicHttpBinding and the WSHttpBinding.
This is very important as the BasicHttpBinding has some major drawbacks compared to the WSHttpBinding. From the functional view it makes no difference, it’s just a client invoking an operation on a service, but there is a world of difference concerning the low level exchange of SOAP packets to achieve this.

BasicHttpBinding

BasicHttpBinding is there only to support the old .ASMX style of working and aimed for clients which do not have .NET 3.0 installed. As lots of Windows 2000, which cannot run .NET 3.0, are still out there this is the only way to work with WCF. So the BasicHttpBinding it’s there mainly for compatibility reasons.
ASMX (without the WS enhancements) does not support secure messaging. When a client calls an operation on a service, all data in the payload is send as a plain XML, human readable, SOAP packet.
It also does not support reliability and ordered delivery.
When a call is lost somewhere, the client is not informed and just waits for a timeout and cannot know for sure if the call has arrived at the server and if the logic behind it got executed.
Also lacking in the basic profile is ordered delivery. This means when a client fires multiple calls to the service it’s not guaranteed that they arrive in the same order. Maybe somewhere a router could drop a packet allowing the second call to arrive earlier than the retransmission of the first. This can lead to disasters, which cannot be allowed in enterprise solutions.

WSHttpBinding
The WSHttpBinding fully supports these requirements on security, reliability and ordered delivery. Some of them as default, others have to be configured.
WSHttpBinding uses (as the name implies) the WS-* protocols. This results in having some additional handshake messaging and This means that not only SOAP requests are sent for the operation calls but also to have the client and service agree on some context and to inform each other on the success of the calls.

WCF Code
I have created new WCF service for clarifying the difference between them. My WCF example is very simple it just one class contain one method which calculate the age by taking birthday as string parameter. You can find it in the below list of codes  
    [ServiceContract]
    interface ITestServiceContract
    {
        [OperationContract]
        int GetAge(string aString);
    }

    class TheService : ITestServiceContract
    {
        public int GetAge(string aString)
        {            Return “25”;        }  

 }

Here you can find the request and response xml message using BasicHttpBinding
Request sample

<s:Envelope xmlns=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
  <s:Body>
    <GetAge xmlns=”http://tempuri.org/”><aDateTime>01/01/1983</aDateTime></GetAge&gt;
  </s:Body>
</s:Envelope>

Response sample

<s:Envelope xmlns=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
  <s:Body>
    <GetAgeResponse xmlns=”http://tempuri.org/”&gt; <GetAgeResult>25</GetAgeResult></GetAgeResponse>
</s:Body>
</s:Envelope>

Now you can notice that this xml messages is very simple no security no encryption also it does not has acknowledge of the arriaval.
Also you can see the request and response using WSHttpBinding in the below image

WCF Binding: BasicHttpBinding vs WsHttpBinding

WCF Binding: BasicHttpBinding vs WsHttpBinding

As said, this behavior comes for free by using WCF, the developer does not have to know how this is done. Compared the ASMX this is a huge step forward. It would be hard to develop this yourself without WCF and if you would succeed in this is, it would be influencing the functional code.
Now you can see the difference between them for reliability and ordering from the below image

WCF Binding: BasicHttpBinding vs WsHttpBinding order

WCF Binding: BasicHttpBinding vs WsHttpBinding order

For BasicHttpBinding you can notice that the request and response done without any acknowledge or ordering.
But for  WSHttpBinding you will find hand check context for acknowledge and ordered responses for each request.

I hope this help.

May 19, 2009 Posted by | WCF | , , | 10 Comments

   

Follow

Get every new post delivered to your Inbox.