- 浏览: 194061 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
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 9251.编辑文本文件users,拷贝至SWDIR/util目录,内 ... -
TIBCO iProcess如何使用SSO
2012-10-09 11:11 812需要在客户端安装匹配版本和平台的SSO,安装完后,在安装目录有 ... -
TIBCO iProcess的table和list被lock了怎么办
2012-09-29 09:57 854去数据库找到表flag_table,将area_locked列 ... -
TIBCO iProcess如何增加workspace的server连接信息
2012-09-29 09:53 1085在windows注册表,打开如下key: HKEY_LOCA ... -
Java Web 服务: Axis2 中的 JAXB 和 JAX-WS
2012-01-10 13:30 870请参考http://www.ibm.com/developer ... -
RPC/编码、RPC/文字、文档/文字?应该采用哪一种?
2012-01-09 17:17 919请参考:http://www.ibm.com/develope ... -
Difference Between RPC and Document
2012-01-09 16:56 1037RPC vs Document RPC and doc ... -
关于JAX-WS和JAX-RPC
2012-01-09 16:36 1008关于JAX-WS和JAX-RPC的区别和联系,请参考: We ... -
WS-Specifications
2011-12-21 13:51 985大部分WS-*规范还处于草稿阶段,但是有些产品已经开始支持某些 ... -
Install TIBCO AMX-BPM on Silver Fabric
2011-12-03 05:16 11241. Install TIBCO Silver Fabr ... -
BPM相关概念
2011-10-19 16:41 4239最近在学习TIBCO的ActiveMatrix BPM,以下是 ... -
BPMN,BPEL,XPDL
2011-08-30 10:33 3021参考: XPEL: http://en.wik ... -
TIBCO SPM & BWSE installation
2011-06-17 16:05 1007ems 5.1.5 tra 5.6.0 tra 5.6.1 ...
相关推荐
WCF服务应用程序三种绑定方式NetTcp、basicHttpBinding、wsHttpBinding
BasicHttpBinding绑定测试源码
通过WCF BasicHttpBinding八步实现windows认证,想要了解WCF安全的朋友可以下载
在IIS7及以上版本服务器中提供了基于WAS的无.SVC文件的WCF服务激活功能,能够提供基于HTTP和非HTTP协议的访问,通过添加Windows Server AppFabric可以更方便的管理WCF服务
代码中实现了在 WCF 中实现可靠 Session 的测试用例,其中也涉及到如何将一个 WCF 服务发布到 IIS 中,目前唯一不能确定的就是在 NLB 的环境中是否也可以实现可靠 Session ,如果哪位网友有这样的资料,也希望共享...
basichttpbinding_ioperationservice wsopertion conn.createinstance(wsopertion,'basichttpbinding_ioperationservice') fhz =wsopertion.openRoomOperate("{'areaid':'1','roomcode':'"+ls_roomcode+"','...
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IResumeImport" contract="ResumeImportService.IResumeImport" name="BasicHttpBinding_IResumeImport" /> <!--...
应用WCF跳过服务器权限配置,在服务器端将excel转换成pdf,这是服务器端,客户端引用如下代码: ChannelFactory<IService> factory = new ChannelFactory( new BasicHttpBinding(), "http://localhost:9999/myservice"...
<endpoint address="WCFServices" bindingConfiguration="BasicHttpBinding_IWCFServices" binding="basicHttpBinding" contract="RuralService.IWCFServices" /> <baseAddresses> </baseAddresses&...
<endpoint address="WCFServices" bindingConfiguration="BasicHttpBinding_IWCFServices" binding="basicHttpBinding" contract="RuralService.IWCFServices" /> <baseAddresses> </baseAddresses&...
通过使用BasicHttpBinding,除了能让WCF客户端访问之外,还增加了WSDL的访问方式。Nginx集群让WCF客户端具备用户名密码验证的同时,达到负载均衡分布式处理的效果。
本书所附光盘范例 第4章(\C04) 示例描述:本章介绍LINQ的基本语法和使用。 UseQueryExpression 演示LINQ表达式语法的使用。 UseMethodSynax 演示LINQ方法语法的使用。 ...示例描述:本章介绍LINQ to ADO.NET...
客户端以BasicHttpBinding访问Nginx的域名zhyongfeng.com/fileupload,然后Nginx进行负载均衡,将消息分发到后端任意一台WCF上传下载服务器的PC机,然后进行上传文件至“冷数据”处,又从“冷数据”处下载文件。
目标: 1.简单的网站嵌入单件silverlight...2.网络传输使用wcf服务,使用(basicHttpBinding) 2.1.支持使用基于流的上传与下载资源(图片,视频) 3.使用sql server 2005作为数据存储. 3.1.使用linq to sql进行数据库操作.
1、添加一个App.config配置文件。 2、配置服务... 代码如下:<?xml version=”1.0″ encoding=”utf-8″ ?> <basicHttpBinding> ”WharfWSBeanBinding”> </basi
<endpoint address="" binding="basicHttpBinding" contract="TestServer.ICalculator"> <!--TestServer.ICalculator服务定义的接口,根据自己定义进行修改--> <baseAddresses>...
只支持BasicHttpBinding 21、Silverlight(23) - 2.0通信之调用WCF的双向通信(Duplex Service) 介绍 Silverlight 2.0 调用 WCF 的双向通信服务(Duplex Service) 。 开发一个服务端主动向客服端发送股票信息的程序,...