Kurt Claeys

DEVITECT.NET

  Home  |   Contact  |   Syndication    |   Login
  125 Posts | 43 Stories | 161 Comments | 13 Trackbacks

News

I'm a .NET architect / developer from Belgium and also trainer in .NET topics.

Kurt CLAEYS

 



view my trainer profile on TrainerExchange.com
 

Join Me at Tech·Ed EMEA Connect for Developers!

View Kurt CLAEYS's profile on LinkedIn


Being ...





 


Working ...


and



Reading ...



Riding ...

Tag Cloud


Article Categories

Archives

Post Categories

Links

 

The first thing developers starting to implement Windows Communication Foundation (WCF) should know is 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 is there only to support the old .ASMX style of working (based on WS-BasicProfile 1.1) 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.

But you have to be familiar with the idea that this basic profile binding is out-of-date and that the protocol does not have enough quality on board to support the requirements of enterprise oriented services, which can have a high SLA.

ASMX does not support secure messaging (I mean by default, without the WS enhancements). When a client calls an operation on a service, all data in the payload is send as a plain XML, human readable, SOAP packet. Scary? Isn’t? 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 can not 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.

In a sentence: do not use basicHttpBinding binding.

The WSHttpBinding fully supports these requirements on security, reliability and ordered delivery. Some of them as default, others have to be configured. But remember this tuning does not influence the functional development; it's all done under the covers!

So there is no excuse to not use the WSHttpBinding.

WSHttpBinding uses (as the name implies) the WS-* protocols. This results in having some additional handshake messaging and other ping-pong exercises (you got it, I got it, you got it, I got it ... as Juval Lowy would say this) to accomplish this. 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.

To fully understand when these extra messages are send and what they are carrying, we can have a closer look at the SOAP messages by using a tool like HTTP Analyzer. This great tool allows you to capture the HTTP traffic and dive into the SOAP packets on the wire.

You can download a demo version of HTTP Analyzer at http://www.ieinspector.com/httpanalyzer/index.html

To experiment on these issues I created an application, which has some scenarios to demonstrate the differences on these bindings. You can download this VS2005 solution here.

I created 3 proxy-service scenarios, all of them exposing the same ServiceOperation and using the same really simple implementation.

[ServiceContract]
interface ITestServiceContract
{
    [OperationContract]
    int DoSomethingInTheService(int aNumber, string aString);

    [OperationContract]
    string DoAnotherThingInTheService(int aNumber, string aString);
}

class TheService : ITestServiceContract
{
    public int DoSomethingInTheService(int aNumber, string aString)
    {
        return aNumber * 10;
    }

    public string DoAnotherThingInTheService(int aNumber, string aString)
    {
        return string.Format("I got {0}", aString);
    }
} 

1. Using BasicHttpBinding (the ASMX style)

Code to start the service (I’m not using any config here, the service is running self hosted in a executable and configuration of binding and endpoint is done programmatically).


* The ServiceHost

ServiceHostBasic = new ServiceHost(typeof(TheService));
BasicHttpBinding binding;
binding = new BasicHttpBinding();
ServiceHostBasic.AddServiceEndpoint(typeof(ITestServiceContract), binding, "http://localhost:9000/ServiceHostBasic");

* The client creates a proxy

EndpointAddress endpointAddress;
endpointAddress = new EndpointAddress(new Uri("http://localhost:9000/ServiceHostBasic"));
BasicHttpBinding binding;
binding = new BasicHttpBinding();

ProxyBasic = new TheProxy(binding,endpointAddress);

* The client calls the operations

int a;
a = ProxyBasic.DoSomethingInTheService(100, "test");
string s;
s = ProxyBasic.DoAnotherThingInTheService(100, "test");

* The client closes the proxy.

ProxyBasic.Close();

Lets examine this scenario in detail. Doing all of this results in 2 messages traveling over the wire. One for the first call (DoSomethingInTheService) another for the second one (DoAnotherThingInTheService).

ss1

Both messages transport the call and the needed data to the service.

Content of the request for the second message (as an example, this is comparable to the first message) :

ss2

Content of the response for the second message:

ss3

Hmm, no security, not encrypted. The client cannot know whether the call arrived at the service, as this is a kind of fire and forget situation. No acknowledgement of the arrival of the call back to the client.


2. Using default WSHttpBinding.

 

* The ServiceHost
ServiceHostWS = new ServiceHost(typeof(TheService));
WSHttpBinding binding;
binding = new WSHttpBinding();
ServiceHostWS.AddServiceEndpoint(typeof(ITestServiceContract), binding, "http://localhost:9000/ServiceHostWS");

ServiceHostWS.Open();

* The client creates a proxy

EndpointAddress endpointAddress;
endpointAddress = new EndpointAddress(new Uri("http://localhost:9000/ServiceHostWS"));
WSHttpBinding binding;
binding = new WSHttpBinding();

ProxyWS = new TheProxy(binding, endpointAddress);

The rest of the code is the same. What has gone over the wire now? This results in 6 messages and their answers.

ss4

Message 1,2 and 3 is a handshake sequence to establish the security context. This handshake is using the Web Service Secure Conversation Languages build on the WS-Security and WS-Trust protocols.

In this part of a message 1 you can see the client asks for a security token.

 ss5b

The answer for this is a RequestSecurityTokenResponse.

ss6

The 2 following SOAP messages (message 2 en 3) complete this handshake.

Message 4 and 5 are the operation calls, but the data is now encrypted in a way the service infrastructure (=WCF) can decrypt this before sending it in the operation.

 cypherdata

Message 6 is again related to the securitycontext. But important to notice that message 6 is sent when closing the proxy. So the service can release the securitycontext.

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.

This is the default behavior of the WSHttpBinding. But what about the reliability and ordered delivery?

3. Using default WSHttpBinding with the reliableSessionEnabled flag on.

When instantiating the WSHttpBinding you can set the reliableSessionEnabled flag to true. This instructs the WCF client to have the messages sent in a reliable session. This means that the client gets informed when the message arrives so there is no doubt whether the serviceoperation has done it’s job.

ss8

* The ServiceHost

ServiceHostWSReliable = new ServiceHost(typeof(TheService));
WSHttpBinding binding;
binding = new WSHttpBinding(SecurityMode.Message, true);
ServiceHostWSReliable.AddServiceEndpoint(typeof(ITestServiceContract), binding, "http://localhost:9000/ServiceHostWSReliable");

ServiceHostWSReliable.Open();

* The client creates a proxy

EndpointAddress endpointAddress;
endpointAddress = new EndpointAddress(new Uri("http://localhost:9000/ServiceHostWSReliable"));
WSHttpBinding binding;
binding = new WSHttpBinding(SecurityMode.Message, true);

ProxyWSReliabable = new TheProxy(binding, endpointAddress);

The only difference is this code compared to scenario 2 is in providing the parameters to the constructor of the binding. This at the client side and the service side.

This results in 9 messages and their answers, of which only 2 messages are the actual calls to the operations.

ss9

Message 1 to 3: Again this is the security context handshake like in the previous scenario.

Message 4: This message asks the service to create the sequence, so it knows it can expect multiple messages that are part of the same sequence.

createsequence

And the answer on this:

createsequenceresponse

Message 5 and 6 are again the encrypted calls to the operations. But notice that each message is carrying a sequence number.

The first operation:

ss10

The second operation:

ss11

Message 7 is the client asking to the service to acknowledge the 2 messages it just has send it.

This message (and the subsequent messages) is send when the proxy is closed. So remember its necessary to close your proxy always!

ss12

On which the service reacts by sending its acknowledgement:

ss13

Message 8 is again the client telling to the service it got its confirmation so both part can be sure the messages are delivered. This is what reliability is about.

Message 9 is as in the previous scenario to release the securitycontext at the service.


Summary (considering 2 calls to an ServiceOperation)

1. BasicHttpBinding (2 messages)

sum1

2. Default WSHttpBinding (6 messages)

sum2

3. Default WSHttpBinding with Reliable Session Enabled (9 messages)

sum3

Some remark: Although you can set the securityMode when creating the BasicHttpBinding for the service, you cannot use this without having either SSL on the IIS to implement for transort level security or implement the WS-enhancement stack on the client yourself. So out-of-the box ASMX services have this basic non-secure behavior. With WCF this comes all for free with the WSHttpBinding.

 

cu (happy coding)

posted on Tuesday, April 22, 2008 8:01 AM

Feedback

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 6/2/2008 4:22 PM flycode
In my project, I used the WSHttpBinding, the service will invoke the a interface provided by other company. it will last two minutes, then it will throw a exception like this:

Exception occured in web site tier : An error occurred while receiving the HTTP response to http://localhost/Service/tService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.


there are some security context information in the call stack.

So I used the basicHttpBing, it works well..


I don`t know why..anyway thanks a lot.


# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 7/18/2008 5:55 AM Mike Jones
I understand your concerns about basicHttpBinding vs WSHttpBinding, but which one should be used in a load balanced environment?

From what I see, the two main advantages of WsHttpBinding are secure sessions and reliable sessions. MSDN documentation (http://msdn.microsoft.com/en-us/library/ms730128.aspx) says to disable both. In my mind, that sounds like falling back to basicHttpBinding, yielding no advantage whatsoever to WsHttpBinding.

What do you think?

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 8/13/2008 7:42 AM thanh
You can only use basic http binding if you want to use streaming.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 10/2/2008 6:27 PM Vamshi Kotagiri
I have a basic knowledge on webservices. Its a very good article that i understand clearly without a basic knowledge about the bindings.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 11/12/2008 11:56 AM Coffee_fan
Unfortunately, Silverlight 2.0 only seems to support BasicHttpBinding.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 12/9/2008 9:50 PM Naibedya
Nice article

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 12/10/2008 4:44 AM Bobby
Nice article. We had a issue with large data sending over web service using WS, was giving timeout error after reaching a certain point, ultimately switch to Basic.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 12/12/2008 8:01 AM Ed
Looks like we are going to be forced to use BasicHttpBinding to support Silverlight. grrrr

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 12/13/2008 4:47 AM Gabriel
Excellent article which compares both the binding using examples

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 1/7/2009 8:56 PM Rajiv kumar
Very good article.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 1/21/2009 8:32 AM Kirk
Have you did any performance evaluations comparing basicHTTP binding to WSHttpBinding? Good article, we'll written...

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 1/28/2009 3:16 AM Mike
WSHttpBinding is not supported in the Compact WCF framework. AKA (Mobile devicess)



# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 3/3/2009 12:33 AM Abugov
Ram,
I think u've misunderstood, u are talking about packets, Kurt was talking about messages (2 separate one-way calls from client to service can arrive in reverse order).

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 4/19/2009 9:13 PM Baris Gulecyuz
very very very thanks for special information

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 5/29/2009 9:56 AM erz
Ram, TCP does its best effort in delivery, and it guarantees order of the packages inside a session. But who haven't got an http 404? This is low-level package processing, but can have drop-outs between sessions, and yes, they can arrive in different order if there is a reconnection between the requests. That's what WCF addresses with wsHttpBinding.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 6/2/2009 9:26 AM Carsten Sonne Larsen
Not everyone is so happy about WS-*

Martin Fowler gave the nick name WS Death Star

http://tssblog.techtarget.com/index.php/xmlweb-services/ws-death-star-sited-at-tss-java-symposium-at-barcelona/


# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 6/8/2009 7:20 AM Mukund Kumar
This is the very good article.

I am using WsHttpBindings in my web application.
When i am trying ot save the information, first four time request is working fine. mins record saved properly in the data base but on fifth and sixth hit on services UI get hanged and time out error thrown. so what is the reason?

Please help me out on this.

Thanks
Mukund Kumar


# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 7/1/2009 1:26 AM Cooper.Wu
great article,
great tests.


# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 7/4/2009 2:22 AM Utkarsh
Great article.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 7/17/2009 5:07 AM Nilav Ghosh
Have you did any performance evaluations comparing basicHTTP binding to WSHttpBinding. Does WSHttpBinding scale up well? From a lot of posts it does seem to be a peoblem. Is it so? ...(By the way the article was very well written ...enjoyed reading it)

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 7/20/2009 9:49 PM Amin Sayed
Superb..!! Excellent..!! I guess this is enough to define how beautifully the article is presented.... Thanks a lot...!!!

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 7/30/2009 1:27 PM Luke Venediger
Nice article, but it's a bit misleading to imply that basichttpbinding leaves your messages out in the open when SSL seems to work pretty well.

I'd rather have that than 6 (yes six!!!) messages just to deliver my payload. Actually, I'd rather not use WCF at all.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 8/5/2009 12:40 AM links of london
I was sure this connection string was coming from some "higher" location, overriding my value, and then while searching google I came across this awesome post from Scott.

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 8/21/2009 7:01 AM Dex
"When a call is lost somewhere, the client is not informed and just waits for a timeout and can not 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."

Hello i'm new to WCF, does this means BasicHttBinding is faster than WSHttpBinding? beacause BasicHttBinding sound like a UDP which is unreliable.

# ed hardy 10/19/2009 8:34 PM ed hardy Shoes
Thank you!

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 10/20/2009 12:24 AM links
dsfa sterling silver links of london charmsbracelets are a modern, grown-up take on the friendshiplinks of london ring bands kjlkjoiulk owjlkjm la

# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 10/21/2009 10:11 PM links
"Manufactured by: Classic <a href=""http://www.linksoflondonstore.com/links-of-london-rings-c-7/sweetie-finger-ring-p-235"">links of london <a href=""http://www.linksoflondonstore.com/links-of-london-necklaces"">links of london necklacessweetie ringCharms 925 Sterling Silver Or 18CT Gold.
100% High Quality & Authentic Guarantee.
Free Shipping for Over Orders £49
FREE Exchange or Return within 10 days" bvnn


# re: WCF : BasicHttpBinding compared to WSHttpBinding at SOAP packet level. 10/31/2009 7:58 PM Rajiv Ramachandran
Excellent description. Thank you for make me understand he concepts.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: