Click here to Skip to main content
11,703,632 members (70,789 online)
Click here to Skip to main content

Difference between BasicHttpBinding and WsHttpBinding

, 18 Jun 2012 CPOL 387.9K 3.9K 177
Rate this:
Please Sign up or sign in to vote.
Difference between BasicHttpBinding and WsHttpBinding.

Table of Contents

Introduction and Goal

WCF has introduced lot of bindings and protocols. This article will concentrate on two important protocols BasicHttpBinding and WsHttpBinding which look similar but have some huge fundamental differences. We will first start with the difference and then we will create a small project and see how the differences look practically.

Nowadays I am distributing my 400 questions and answers ebook which covers major .NET related topics like WCF, WPF, WWF, AJAX, core .NET, SQL Server, architecture, and a lot more. I am sure you will enjoy this ebook.

Pre-requisite

In case you are new to WCF, please do read the basics from the below given links. Basics of WCF are not in the scope of this article:

Difference between BasicHttpBinding and WsHttpBinding

If we want to summarize in one sentence, the difference between WsHttpBinding and BasicHttpBinding is that WsHttpBinding supports WS-* specification. WS-* specifications are nothing but standards to extend web service capabilities.

Below is a detailed comparison table between both the entities from security, compatibility, reliability, and SOAP version perspectives.

Criteria BasicHttpBinding WsHttpBinding
Security support This supports the old ASMX style, i.e., WS-BasicProfile 1.1. This exposes web services using WS-* specifications.
Compatibility This is aimed for clients who do not have .NET 3.0 installed and it supports wider ranges of clients. Many of the clients like Windows 2000 still do not run .NET 3.0. So an older version of .NET can consume this service. As it is built using WS-* specifications, it does not support wider ranges of clients and it cannot be consumed by older .NET versions less than 3 version.
SOAP version SOAP 1.1 SOAP 1.2 and WS-Addressing specification.
Reliable messaging Not supported. In other words, if a client fires two or three calls you really do not know if they will return back in the same order. Supported as it supports WS-* specifications.
Default security options By default, there is no security provided for messages when the client calls happen. In other words, data is sent as plain text. As WsHttBinding supports WS-*, it has WS-Security enabled by default. So the data is not sent in plain text.
Security options
  • None
  • Windows – default authentication
  • Basic
  • Certificate
  • None
  • Transport
  • Message
  • Transport with message credentials

One of the biggest differences you must have noticed is the security aspect. By default, BasicHttpBinding sends data in plain text while WsHttpBinding sends it in an encrypted and secured manner. To demonstrate the same, let's make two services, one using BasicHttpBinding and the other using WsHttpBinding and then let's see the security aspect in a more detailed manner.

We will create a small sample to see how BasicHttpBinding sends data in plain text format and how WsHttpBinding encrypts data.

Note: By default, security is not enabled on BasicHttpBinding for interoperability purposes. In other words, it is like our old webservice, i.e. ASMX. But that does not mean we cannot enable security in BasicHttpBinding. Sometime back, we i had  written an article on how to enable security on BasicHttpBinding.

Five Steps to See the Actual Difference between BasicHttpBinding and WsHttpBinding

In order to understand the real differences between these entities, we will do a small project. In this project, we will create two WCF services, one service using BasicHttpBinding and the second service using WsHttpBinding.

Step 1: Let's first create a simple service using BasicHttpBinding. For that, we just create a simple WCF project and then modify the ServiceModel element as shown below. You can see in the endpoint tag that we have specified basicHttpBinding as the protocol.

<system.serviceModel>
<services>
<service name="WCFBasicHttpBinding.Service1" 
	behaviorConfiguration="WCFBasicHttpBinding.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="WCFBasicHttpBinding.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="WCFBasicHttpBinding.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>

Step 2: We also need to create one more service using WsHttpBinding. For that, you do not need to do anything special as such. By default, a WCF project is created using WsHttpBinding. Below is how the Web.config file looks like. You can see how the endpoint tag is using wsHttpBinding.

<system.serviceModel>
<services>
<service name="WCFWsHttpBindingHttps.Service1" 
	behaviorConfiguration="WCFWsHttpBindingHttps.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" contract="WCFWsHttpBindingHttps.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="WCFWsHttpBindingHttps.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>

Step 3: We will not be creating any new methods in both the services. We will just use the default code created by the WCF template. So both these services will have a GetData function which returns a string. The GetData function is a default function created WCF project.

public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}

Step 4: Now that our services are created, we need to create a client which will consume this service. So we have created a simple web application and we have added two references, one is a service reference, i.e., WsHttpBinding, and the second is a web reference, i.e., BasicHttpBinding. In this example I have used a web reference to add BasicHttpBinding but you can do this by using Add Service Reference as well. I have used Add Web Reference to just prove that BasicHttpBinding is actually backwards compatible with old web services. 

We will add two buttons on the default ASPX page. One button will call the HTTP service and the other will call the WsHttp service. Below is how the function GetData is called in both the button clicks.

Step 5: Now that we are ready with the complete project, it is time to sniff and see how data is transported between the client and the service in both scenarios. Let's download a simple HTTP data recorder from here. We will then click both the buttons one by one and record the data transfer using httpanalyzer. You can see the posted data is in simple plain XML format for the basic HTTP protocol and it is in an encrypted format for the wshttp protocol.

In other words, avoid BasicHttp as far as possible.

Consideration When to Use BasicHttp and WsHttp

If you are looking for backwards compatibility and to support a lot of clients, then basic HTTP binding is the way to go, or else WsHttp is a great way to start if you are seeing your clients made in .NET 3.0 and above.

History

  • 13th May, 2009: Initial post.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shivprasad koirala
Architect http://www.questpond.com
India India

I am an ex-Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos, writing books and corporate trainings. Do visit my site for 
.NET, C#, Design Pattern, WCF, Silverlight, LINQ, ASP.NET, ADO.NET, SharePoint, UML, SQL Server  training 
and Interview questions and answers


You may also be interested in...

Comments and Discussions

 
Question[My vote of 1] BasicHttpBinding and security mode Pin
Leonardo Paneque4-Sep-14 10:34
memberLeonardo Paneque4-Sep-14 10:34 
BugLink is dead Pin
sdrzmw30-Aug-14 21:18
membersdrzmw30-Aug-14 21:18 
QuestionVery good example but what if service is hosted on different machine? Pin
saiduth4-Jun-14 21:08
membersaiduth4-Jun-14 21:08 
GeneralMy vote of 5 Pin
maiteib25-Feb-14 0:33
membermaiteib25-Feb-14 0:33 
QuestionSangeeta.bhatt@akaaraconsulting.com Pin
Member 99259319-Feb-14 17:59
memberMember 99259319-Feb-14 17:59 
QuestionWhat is WS-* ? Pin
Karthik Skandakumar23-Jan-14 1:49
memberKarthik Skandakumar23-Jan-14 1:49 
QuestionDoes SSL/TLS cover Data-in-Transit Pin
bjm2438-Aug-13 5:19
memberbjm2438-Aug-13 5:19 
GeneralMy vote of 5 Pin
Mohammed Hameed10-Jul-13 2:37
professionalMohammed Hameed10-Jul-13 2:37 
GeneralMy vote of 5 Pin
Rockstar_4-Jun-13 22:41
memberRockstar_4-Jun-13 22:41 
Questionvery nice description Pin
swapymore_016-Feb-13 17:34
memberswapymore_016-Feb-13 17:34 
QuestionPossible to have both Basic and WS on same service? Pin
Bustell14-Nov-12 3:34
memberBustell14-Nov-12 3:34 
AnswerRe: Possible to have both Basic and WS on same service? Pin
Mohammed Hameed10-Jul-13 2:38
professionalMohammed Hameed10-Jul-13 2:38 
QuestionSecurity Pin
saikat Malakar9-Nov-12 1:35
membersaikat Malakar9-Nov-12 1:35 
QuestionWhat an article Pin
saikat Malakar9-Nov-12 1:24
membersaikat Malakar9-Nov-12 1:24 
GeneralMy vote of 4 Pin
Sankit7-Oct-12 23:57
memberSankit7-Oct-12 23:57 
GeneralMy vote of 5 Pin
Veena Khanna18-Jul-12 21:17
memberVeena Khanna18-Jul-12 21:17 
GeneralMy vote of 5 Pin
fredatcodeproject16-Jul-12 1:24
memberfredatcodeproject16-Jul-12 1:24 
QuestionMy vote of 5 Pin
Sathishkumar_P6-Jul-12 3:10
memberSathishkumar_P6-Jul-12 3:10 
Nice article
GeneralMy vote of 5 Pin
amitgajjar29-Jun-12 2:36
memberamitgajjar29-Jun-12 2:36 
QuestionSilverlight Pin
Dearthdog25-Jun-12 10:57
memberDearthdog25-Jun-12 10:57 
GeneralVery Informative! Pin
Omar Gamil22-Jun-12 10:08
memberOmar Gamil22-Jun-12 10:08 
Questionhow can I make the soap messsage show up HTTP 1.0 in the message instead of HTTP 1.1. Pin
Aftab Jahangir22-Jun-12 9:35
memberAftab Jahangir22-Jun-12 9:35 
Question[My vote of 1] Please fix your false statement .... Pin
Marc Scheuner18-Jun-12 9:48
memberMarc Scheuner18-Jun-12 9:48 
AnswerRe: [My vote of 1] Please fix your false statement .... Pin
Shivprasad koirala18-Jun-12 17:16
memberShivprasad koirala18-Jun-12 17:16 
GeneralRe: [My vote of 1] Please fix your false statement .... Pin
Marc Scheuner18-Jun-12 19:05
memberMarc Scheuner18-Jun-12 19:05 
Questionvote 5 Pin
.NetStars11-Jun-12 8:45
member.NetStars11-Jun-12 8:45 
GeneralMy vote of 5 Pin
Clodetta del Mar26-Apr-12 21:43
memberClodetta del Mar26-Apr-12 21:43 
GeneralMy vote of 5 Pin
manoj kumar choubey16-Apr-12 3:21
membermanoj kumar choubey16-Apr-12 3:21 
GeneralMy vote of 5 Pin
jrgrobinson2-Apr-12 12:26
memberjrgrobinson2-Apr-12 12:26 
GeneralMy vote of 5 Pin
shailesh4all14-Jan-12 13:56
membershailesh4all14-Jan-12 13:56 
GeneralMy vote of 5 Pin
Sandeep Ramani22-Sep-11 2:57
memberSandeep Ramani22-Sep-11 2:57 
QuestionAny performance difference? Pin
Rahul D.24-Aug-10 5:57
memberRahul D.24-Aug-10 5:57 
Questionwhy to avoid basichttpbinding? Pin
masaniparesh8-May-10 21:26
membermasaniparesh8-May-10 21:26 
AnswerRe: why to avoid basichttpbinding? Pin
Shivprasad koirala8-May-10 21:53
mvpShivprasad koirala8-May-10 21:53 
GeneralRe: why to avoid basichttpbinding? Pin
masaniparesh8-May-10 22:09
membermasaniparesh8-May-10 22:09 
QuestionHow Can I authenticate in basicHttpBinding? Pin
ramesh naamala12-Dec-09 0:24
memberramesh naamala12-Dec-09 0:24 
GeneralAbout the Add Service Reference Pin
Johan Fourie19-May-09 15:13
memberJohan Fourie19-May-09 15:13 
GeneralRe: About the Add Service Reference Pin
Shivprasad koirala19-May-09 18:22
memberShivprasad koirala19-May-09 18:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 18 Jun 2012
Article Copyright 2009 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid