日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WCF系列(一)BasicHttpBinding 和 WsHttpBinding 的不同点

發布時間:2024/7/5 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WCF系列(一)BasicHttpBinding 和 WsHttpBinding 的不同点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
aaaaaaaaaaaaaaaaaa

?

WCF系列(一)【翻譯】BasicHttpBinding 和 WsHttpBinding 的不同點

2010-02-21 12:23 by Virus-BeautyCode,?20206?閱讀,?7?評論,?收藏,?編輯

?

原文地址: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的基礎知識點了:

  • Windows Communication Framework (WCF) - Part 1
  • Windows Communication Framework (WCF) - Part 2

3、BasicHttpBinding和WsHttpBinding的不同點

  如果非要用一句話概述BasicHttpBinding和WsHttpBinding的不同的話,那就是WsHttpBinding支持WS-Security specifications,WS-Security specifications具有擴展web service的能力。

  下面的表格式是對兩者在安全、兼容性、可靠性和SOAP版本方面的比較。

  

CriteriaBasicHttpBindingWsHttpBinding
Security supportThis supports the old ASMX style, i.e. WS-BasicProfile 1.1.This exposes web services using WS-* specifications.
CompatibilityThis 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 versionSOAP 1.1SOAP 1.2 and WS-Addressing specification.
Reliable messagingNot 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 optionsBy 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

?

?

  兩者之間最大的不同你一定已經注意到了,那就是安全。默認情況下,BasicHttpBinding發送的是明文數據,而WsHttpBinding發送的是加密和更加安全的數據。為了證明這一點,我們新建兩個服務,一個使用BasicHttpBinding,一個使用WsHttpBinding,然后詳細查看一下他們的安全方面。

  我們創建一個小例子,看看basicHttpBinding是如何明文發送數據的,wsHttpBinding是如何加密數據的。

  說明:默認情況下,使用basicHttpBinding的時候,安全是沒有啟用的。換句話說,它很像以前的webservice,也就是.asmx。但是不意味著我們不能啟用安全。稍后,我會寫一篇關于basicHttpBinding啟用安全的文章。

  

4、通過5步比較他們的不同點

  為了它們之間實際的不同點,我們創建一個小工程。在工程中,創建兩個服務,一個使用basicHttpBinding,一個使用wsHttpBinding。

  

  第一步:使用basicHttpBinding創建一個服務,system.serviceModel配置如下

  

<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的服務,配置如下

  

<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>

?

  第三步:我們不創建任何新函數,就是用默認創建的兩個函數,如下

  

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;
????????}
????}

?

?

  第四步:服務已經創建好了,我們創建一個消費服務的客戶端。在這里,我們創建一個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。

【Blog】http://virusswb.cnblogs.com/

【MSN】jorden008@hotmail.com

【說明】轉載請標明出處,謝謝

?

?

轉載于:https://www.cnblogs.com/wangsea/p/10302047.html

總結

以上是生活随笔為你收集整理的WCF系列(一)BasicHttpBinding 和 WsHttpBinding 的不同点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。