- 浏览: 472657 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (1028)
- [发布至博客园首页] (826)
- [随笔分类]个人生活随笔 (14)
- [网站分类]首页候选区 (26)
- [网站分类]SharePoint (15)
- [网站分类]其他技术区 (6)
- [随笔分类]批处理技巧 (6)
- [随笔分类].net 2.0 (3)
- [随笔分类]SharePoint2007(MOSS2007) (0)
- [网站分类].NET新手区 (6)
- [网站分类]ASP.NET (6)
- [网站分类]架构设计 (18)
- [网站分类]程序人生 (2)
- [网站分类]SQL Server (2)
- WCF (3)
- 编程技巧 (2)
- 模式架构 (2)
- 分析设计 (4)
- 生活随笔 (0)
- 软件工程 (1)
- Android实例 (2)
最新评论
-
zilong0536:
楼主您好:
请问发表博文支持图片的功能怎么实现啊,一直没有思路 ...
新浪微博开放平台开发-android客户端(3) -
nicegege:
小弟 学习了
帮助中国移动设计10086的排队小模块 -
zl7824516:
用什么技术没说啊
通告(公告),消息(站内短信),提醒的设计:通告 -
virusswb:
源码下载: SinaWeibo2 源码下载之后,将后缀改为ra ...
新浪微博开放平台开发-android客户端(3) -
Jimmyxu0311:
找不到源码下载
新浪微博开放平台开发-android客户端(3)
原文地址:Difference between BasicHttpBinding and WsHttpBinding
1、简介
WCF引入了很多的绑定和协议。本文重点讨论两个协议,BasicHttpBinding和WsHttpBinding,他们看起来很相似,但是却有很大的不同。因此,我们首先看一下他们的不同点,然后通过一个小项目看看他们到底有什么不同。
作者还总结了400多个.NET相关的话题,例如:WCF,WPF,WWF,Ajax,Core .NET,SQL Server,Architecture等等。
下载地址:/Files/virusswb/SampleDotNetInterviewQuestionBook.zip
2、预备知识
如果你第一次接触WCF,可以通过下面的链接了解一下相关的知识。在本文就不讲述WCF的基础知识点了:
3、BasicHttpBinding和WsHttpBinding的不同点
如果非要用一句话概述BasicHttpBinding和WsHttpBinding的不同的话,那就是WsHttpBinding支持WS-Security specifications,WS-Security specifications具有扩展web service的能力。
下面的表格式是对两者在安全、兼容性、可靠性和SOAP版本方面的比较。
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 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 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 |
|
|
两者之间最大的不同你一定已经注意到了,那就是安全。默认情况下,BasicHttpBinding发送的是明文数据,而WsHttpBinding发送的是加密和更加安全的数据。为了证明这一点,我们新建两个服务,一个使用BasicHttpBinding,一个使用WsHttpBinding,然后详细查看一下他们的安全方面。
我们创建一个小例子,看看basicHttpBinding是如何明文发送数据的,wsHttpBinding是如何加密数据的。
说明:默认情况下,使用basicHttpBinding的时候,安全是没有启用的。换句话说,它很像以前的webservice,也就是.asmx。但是不意味着我们不能启用安全。稍后,我会写一篇关于basicHttpBinding启用安全的文章。
4、通过5步比较他们的不同点
为了它们之间实际的不同点,我们创建一个小工程。在工程中,创建两个服务,一个使用basicHttpBinding,一个使用wsHttpBinding。
第一步:使用basicHttpBinding创建一个服务,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>
第二步:创建一个WsHttpBinding的服务,配置如下
<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>
第三步:我们不创建任何新函数,就是用默认创建的两个函数,如下
{
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;
}
}
第四步:服务已经创建好了,我们创建一个消费服务的客户端。在这里,我们创建一个WebApplication,添加两个引用,一个是service reference,WsHttpBinding;另外一个是web reference,BasicHttpBinding。请记住,在你右键添加引用的时候,通过service reference添加WsHttpBinding,通过web reference添加BasicHttpBinding。
我们在webapplication的default页面上添加两个button,一个调用HTTP Service,另外一个调用wshttp service。下面是它们如何调用服务的GetData方法。
第五步:到这里我们准备完成这个项目,到了嗅探的时候了,看看数据在客户端和两个服务之间是如何传输的。我们下载并使用HTTP数据记录器,IE Inspector。我们将一个一个的点击button,来记录数据的传输。你将会看到在basicHttpBinding的情况下,数据明文的通过xml发送;在wsHttpBinding的情况下,数据被加密发送。
总之,尽量避免使用BasicHttpBinding。
5、什么时候使用BasicHttpBinding,什么时候使用WsHttpBinding
如果你希望有向后兼容的能力,并且支持更多的客户端,你可以选择basicHttpBinding,如果你确定你的客户端使用的是.NET 3.0甚至更高的话,你可以选择wsHttpBinding。
发表评论
-
NET 应用架构指导 V2 学习笔记(十六) 服务层设计指导
2010-06-04 00:13 521如果你的应用是通 ... -
NET 应用架构指导 V2 学习笔记(十七) 组件设计指导
2010-06-05 00:48 622组件提供了一种将 ... -
NET 应用架构指导 V2 学习笔记(十八) 表现层组件设计指导
2010-06-05 21:09 488本章讲述的是你在设计用户界面组件和表现层逻辑组件的时候应该 ... -
NET 应用架构指导 V2 学习笔记(十九) 表现层组件设计指导
2010-06-06 06:15 5535 决定数据绑定的 ... -
NET 应用架构指导 V2 学习笔记(二十) 业务组件设计指导
2010-06-07 06:58 575前言 业务组件 ... -
微软企业库5.0学习笔记(四十二)异常处理模块
2010-06-14 00:04 800企业库的异常处理 ... -
关于程序员在30岁、35岁之后怎么办的新思考
2010-06-14 10:40 592首先给大家问个好 ... -
NET 应用架构指导 V2 学习笔记(二十四) 跨层关注问题
2010-06-17 20:00 546概况 大部分的 ... -
微软企业库5.0学习笔记(四十三)数据验证模块
2010-06-19 08:07 958概况 任何接受用户或者是其他系统输入的应用,一定要确保 ... -
关于项目进度慢的思考----如何提高整体开发效率
2010-06-21 23:42 764我们都是软件行业 ... -
微软企业库5.0学习笔记(四十四)实战数据验证模块
2010-06-23 19:22 7891 在业务对象上添加验证 添加对程序集【Microso ... -
微软企业库5.0学习笔记(四十五)实战数据验证模块----高级篇
2010-06-24 19:41 9421、添加自定义的提示信息 验证失败的提示信息可以自定义 ... -
面向对象类设计的五大原则(一)单一职责原则Single Responsibility Principle
2010-06-29 15:45 731引言 面向对象类设计,或者说是面向对象设计,有五大原则 ... -
《深入浅出设计模式-中文版》读书笔记 开篇乱弹(一)
2010-07-01 06:42 616oreilly的《Head.First ... -
《深入浅出设计模式-中文版》读书笔记-继承与组合(三)
2010-07-03 16:53 573经过上一次的改造 ... -
《深入浅出设计模式-中文版》读书笔记-观察者模式(四)
2010-07-06 06:34 597今天要接触的是观 ... -
利用attribute实现简单的ORM
2010-07-09 15:27 641我不知道NH的ORM具 ... -
系统内部模块(子系统)之间的耦合以及模块(子系统)划分
2010-07-14 13:02 785题外话 最近已经在努力学习了,学习基本功,学习设计模式 ... -
《深入浅出设计模式-中文版》读书笔记-工厂模式(五)
2010-07-16 12:46 663今天给大家带来的是:工厂模式。 我们在代码中创建一个对 ... -
Head.First.Object-Oriented.Design.and.Analysis《深入浅出面向对象的分析与设计》读书笔记(一)
2010-07-18 21:47 635题外话 又是一本Head.First系列的书,这个系列 ...
相关推荐
通过WCF BasicHttpBinding八步实现windows认证,想要了解WCF安全的朋友可以下载
微软 WCF系列课程 教学 webcast
金旭亮WCF课程系列之WCF概述 仅供下载参考使用
WCF第一步 WCF第一步 WCF第一步 WCF第一步 WCF第一步 WCF第一步
微软 WCF系列课程 教学 webcast
WCF系列学习教程测试代码,适合初学者,如单调服务、序列化、消息队列等等
从零开始学WCF系列,分布式通信传输协议
WCF开发实战系列,手把手教你建立wcf
代码中实现了在 WCF 中实现可靠 Session 的测试用例,其中也涉及到如何将一个 WCF 服务发布到 IIS 中,目前唯一不能确定的就是在 NLB 的环境中是否也可以实现可靠 Session ,如果哪位网友有这样的资料,也希望共享...
WCF (Windows Communication Foundation) :契约, 绑定, 宿主, 异常处理, 异步调用, 双向通讯, MTOM, 流数据传输, 序列化, 实例模型, 会话状态, 并发, 限流, 事务, 安全, 可靠性消息, 消息队列, WCF创建REST, AJAX...
[Addison-Wesley Professional] WCF 3.5 本质论 (英文版) [Addison-Wesley Professional] Essential Windows Communication Foundation For .NET Framework 3.5 ==================================================...
该平台随着Windows Vista操作系统,并且作为.NET Framework 3.0的一部分发布。WCF统一了组件与服务之间如何通讯的开发模型:无论是否是分布式架构,是否需要穿越防火墙访问,或者对于互操作接口的可用 性,WCF都提供...
[Packt Publishing] WCF 4.5 多层服务开发 —— 使用 Entity Framework 技术 第3版 [Packt Publishing] WCF 4.5 Multi-Layer Services Development with Entity Framework 3rd Edition (E-Book) ☆ 出版信息:☆ ...
金旭亮WCF课程系列之WCF概述金旭亮WCF课程系列之WCF概述金旭亮WCF课程系列之WCF概述金旭亮WCF课程系列之WCF概述金旭亮WCF课程系列之WCF概述
wcf一个完整的实例,从服务契约,宿主定义等
WCF Microsoft面向服务的解决方案
一套简单的 WCF 宿主 !一套简单的 WCF 宿主 !一套简单的 WCF 宿主 !一套简单的 WCF 宿主 !一套简单的 WCF 宿主 !一套简单的 WCF 宿主 !
[奥莱理] WCF服务编程 [奥莱理] Programming WCF Services (E-Book) ☆ 出版信息:☆ [作者信息] Juval Lowy [出版机构] 奥莱理 [出版日期] 2007年02月27日 [图书页数] 640页 [图书语言] 英语 [图书格式] ...
WCF服务应用程序三种绑定方式NetTcp、basicHttpBinding、wsHttpBinding