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/”>
<s:Body>
<GetAge xmlns=”http://tempuri.org/”><aDateTime>01/01/1983</aDateTime></GetAge>
</s:Body>
</s:Envelope>
Response sample
<s:Envelope xmlns=”http://schemas.xmlsoap.org/soap/envelope/”>
<s:Body>
<GetAgeResponse xmlns=”http://tempuri.org/”> <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
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
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.
8 Comments »
Leave a Reply
-
Archives
- May 2011 (2)
- January 2011 (2)
- December 2010 (1)
- September 2010 (8)
- August 2010 (1)
- March 2010 (1)
- November 2009 (1)
- October 2009 (3)
- September 2009 (2)
- August 2009 (1)
- July 2009 (7)
- June 2009 (10)
-
Categories
-
RSS
Entries RSS
Comments RSS




nice comparison, thanks for sharing
Thank you for your comment but it will be very nice if you write post about using this two types of binding in old work before
This is really useful even for a non hard core developer..
Thank you for comment
Nice article…explains the difference between the two binding types in a nice way
It is very nice explain and very useful. Thanks
Dear,
Thank you for your comment and you are welcome
Thanks, really nice comparision