- 浏览: 197775 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
sucheng2016:
SYBASE的字段类型 -
sushi1025:
MySQL删除重复数据行,只保留一条 -
793059909:
看不懂,能否简单解释下。更常见的做法是把需要保留的数据放一张临 ...
MySQL删除重复数据行,只保留一条 -
zyllezi:
困扰了好久,终于解决了,多谢博主
使用PHP访问MySQL,Apache httpd.exe报错
Download
Download source code for Difference between BasicHttpBinding and WsHttpBinding
Difference between BasicHttpBinding and WsHttpBinding
Introduction and Goal
Pre-requisite
Difference between BasicHttpBinding and WsHttpBinding
Five steps to see the actual difference between BasicHttpBinding and WsHttpBinding
Consideration when to use BasicHttp and WsHttp
Source code
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. So we will first start with the difference and then we will make a small project and see how the differences look practically.
Now a days 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 lot lot more. I am sure you will enjoy this ebook.
http://www.questpond.com/SampleDotNetInterviewQuestionBook.zip
Pre-requisite
In case you are new to WCF please do read the basics from the below give links. Basics of WCF are not in scope of this article.
http://www.dotnetfunda.com/articles/article221.aspx to see Windows Communication Framework (WCF) - Part 1
http://www.dotnetfunda.com/articles/article222.aspx to see Windows Communication Framework (WCF) - Part 2
Difference between BasicHttpBinding and WsHttpBinding
If we want to summarize in one sentence the difference between ‘WsHttpBinding’ and ‘BasicHttpBinding’ is tha ‘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 perspective.
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 client. Many of clients like Windows 2000 still do not run .NET 3.0. So older version of .NET can consume this service. |
As its built using WS-* specifications it does not support wider ranges of client and it cannot be consumed by older .NET version 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 they will return back in the same order. |
Supported as it supports WS-* specifications. |
Default security options |
By default there is not 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 |
|
|
One of the biggest differences you must have noticed is the security aspect. By default ‘BasicHttpBinding’ sends data in plain text while ‘WsHttpBinding’ sends in 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 do 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 purpose. In other words it like our old webservice i.e. ASMX. But that does not mean we cannot enable security in ‘BasicHttpBinding’. Sometimes back we had a written a article on how to enable security on ‘BasicHttpBinding’ http://www.dotnetfunda.com/articles/article362.aspx
Five steps to see the actual difference between BasicHttpBinding and WsHttpBinding
In order to understand the real differences between both these entities we will do a small project. In this project we will create two WCF service one service using ‘BasicHttpBinding’ and the second service using ‘WsHttpBinding’.
Step1:- So let’s first create a simple service using ‘BasicHttpBinding’. For that we just a create a simple WCF project and then modify the ‘ServiceModel’ element as shown below. You can see in the ‘endpoint’ tag 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 anything special as such. By default 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 out 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’. Please note when you right click to add reference you need to use the ‘Add service reference’ to add ‘WsHttpService’ and you need to add web reference for ‘BasicHttpBinding’.
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 :- So now we are ready with the complete project it is time to sniff and see how data is transported between client and the service in both the scenarios. So let’s download a simple http data recorder from http://www.ieinspector.com/httpanalyzer/download.html . 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 basic http protocol and it’s in an encrypted format for wshttp protocol.
In other words avoid ‘BasicHttp’ as far as possible.
Consideration when to use BasicHttp and WsHttp
If you are looking for back ward compatibility and to support lot of clients then basic http binding is the way to go or else WsHttp is the great way to start if you are seeing your clients made in .NET 3.0 and above.
Source code
Get the source code at the top of this article.
发表评论
-
TIBCO iProcess如何批量创建用户
2012-10-09 15:07 9621.编辑文本文件users,拷贝至SWDIR/util目录,内 ... -
TIBCO iProcess如何使用SSO
2012-10-09 11:11 867需要在客户端安装匹配版本和平台的SSO,安装完后,在安装目录有 ... -
TIBCO iProcess的table和list被lock了怎么办
2012-09-29 09:57 896去数据库找到表flag_table,将area_locked列 ... -
TIBCO iProcess如何增加workspace的server连接信息
2012-09-29 09:53 1106在windows注册表,打开如下key: HKEY_LOCA ... -
Java Web 服务: Axis2 中的 JAXB 和 JAX-WS
2012-01-10 13:30 898请参考http://www.ibm.com/developer ... -
RPC/编码、RPC/文字、文档/文字?应该采用哪一种?
2012-01-09 17:17 933请参考:http://www.ibm.com/develope ... -
Difference Between RPC and Document
2012-01-09 16:56 1068RPC vs Document RPC and doc ... -
关于JAX-WS和JAX-RPC
2012-01-09 16:36 1032关于JAX-WS和JAX-RPC的区别和联系,请参考: We ... -
WS-Specifications
2011-12-21 13:51 997大部分WS-*规范还处于草稿阶段,但是有些产品已经开始支持某些 ... -
Install TIBCO AMX-BPM on Silver Fabric
2011-12-03 05:16 11421. Install TIBCO Silver Fabr ... -
BPM相关概念
2011-10-19 16:41 4281最近在学习TIBCO的ActiveMatrix BPM,以下是 ... -
BPMN,BPEL,XPDL
2011-08-30 10:33 3047参考: XPEL: http://en.wik ... -
TIBCO SPM & BWSE installation
2011-06-17 16:05 1028ems 5.1.5 tra 5.6.0 tra 5.6.1 ...
相关推荐
在这个例子中,客户端会使用BasicHttpBinding绑定来连接服务,通过代理类(如IServiceClient)调用服务的方法。客户端的配置文件(app.config或client.exe.config)可能包含了服务地址、绑定配置和契约类型信息。 *...
本文将详细解析如何通过WCF的BasicHttpBinding实现Windows身份验证,这在需要使用域用户凭证进行安全通信的场景中非常有用。我们将分为八个步骤进行讲解。 **步骤一:创建WCF服务** 首先,我们需要创建一个WCF服务...
2. **服务暴露**:为了使Silverlight客户端能够访问,服务需要通过Silverlight-enabled binding(如BasicHttpBinding或WSHttpBinding)暴露。Silverlight有安全限制,只能使用特定的跨域策略文件来允许跨域调用。 3...
本篇将详细介绍WCF服务的三种主要绑定方式:NetTcp、basicHttpBinding和wsHttpBinding。 1. **NetTcp绑定** NetTcp绑定是WCF中的一种高效、安全的绑定,它主要用于同一网络内的应用程序间通信。NetTcp结合了TCP...
WCF提供了多种传输绑定元素,如NetTCPBinding、BasicHttpBinding、WSHttpBinding等,每种绑定都有其特定的特性和用途。例如,NetTCPBinding提供了高效的双向通信,适合内部网络;BasicHttpBinding则与Web服务标准...
例如,可能有示例代码展示了如何使用BasicHttpBinding或WSHttpBinding,并启用SSL(Secure Sockets Layer)来确保通信安全。 在安全认证方面,Silverlight支持多种身份验证模型,如FormsAuthentication、Windows...
BasicHttpBinding适合简单的、无状态的服务,而WsHttpBinding则提供了更强的安全性和互操作性。 在实际操作中,文件传输可能会涉及大容量的数据流,因此我们需要考虑效率和性能。WCF提供了流传输模式,允许数据以流...
- **互联网**:通常使用BasicHttpBinding或WSHttpBinding,可能需要Message Security配合证书来保证安全。 - **B2B(Business-to-Business)**:WSHttpBinding和WSFederationHttpBinding用于跨组织的交互,支持...
WCF支持多种传输协议,如HTTP、TCP、Named Pipe、MSMQ和Peer-to-Peer,以及多种绑定类型,如BasicHttpBinding、WsHttpBinding和NetTcpBinding等。这些绑定定义了服务如何通过选定的传输协议进行通信,同时也规定了...
WCF服务可以通过配置文件定义各种绑定(如BasicHttpBinding、WSHttpBinding等),以适应不同的通信需求。创建一个WCF服务客户端并调用方法如下: ```csharp using (var client = new MyServiceClient()) { client....
3. **配置SOAP终结点**:在创建代理类后,需要设置终结点信息,包括地址(URL)、绑定(如BasicHttpBinding或WSHttpBinding)和合同(定义服务提供的操作)。例如: ```csharp BasicHttpBinding binding = new ...
2. 配置服务绑定,如basicHttpBinding、wsHttpBinding等,这些绑定默认支持SOAP协议。 3. 设置服务行为,如数据契约、消息契约或服务元数据,以便定义消息格式和交换规则。 **WCF与AJAX和SOAP的结合**: WCF允许在...
对于Silverlight应用,WCF提供了专为Silverlight设计的服务合同和绑定,如Silverlight绑定(BasicHttpBinding、WsHttpBinding等)。使用WCF,开发者可以轻松地创建安全、可靠、事务性的服务,使Silverlight客户端能...
在WCF中,可以设置绑定元素(如BasicHttpBinding、WsHttpBinding等)的UseDefaultWebProxy属性为true,并使用Transport或TransportWithMessageCredential安全模式,结合HTTPS协议来启用SSL/TLS。 在提供的压缩文件...
3. **BasicHttpBinding或WSHttpBinding**: 选择适合Silverlight的绑定类型,BasicHttpBinding通常更简单,而WSHttpBinding支持更多安全特性。 4. **JSON或XML序列化**: Silverlight可以通过配置WCF服务使用JSON...
为了调用这样的服务,客户端需要设置适当的绑定,如BasicHttpBinding或WsHttpBinding,并指定服务的地址。客户端通过代理类或者ChannelFactory来创建与服务的连接,然后就可以调用服务提供的操作。 在处理Web中的...
WCF支持多种绑定,如BasicHttpBinding、WSHttpBinding等。每个绑定都有其默认的安全设置。例如,WSHttpBinding提供了强安全性,包括消息级安全,它可以提供身份验证、加密和完整性保护。在绑定中调整安全设置可以...
2. **配置文件生成**:NetCFSvcUtil会为客户端生成相应的配置文件,包括服务的地址、绑定类型(如BasicHttpBinding、WSHttpBinding等)和行为设置,确保客户端能够正确连接和通信。 3. **数据契约支持**:如果WCF...