WCF服務綁定

WCF服務綁定是一個集合,每個元素定義了服務與客戶端進行通信方式的幾個元素。傳輸元素和一個消息編碼元素各自結合兩個最重要的組成部分。這裏是WCF服務綁定常用的列表。

基礎綁定

基礎約束是由basicHttpBinding的類提供的,這種結合使用HTTP協議進行傳輸爲目的,並代表一個WCF服務作爲一個ASP.NET Web服務(ASMX Web服務),這樣方便ASMX Web服務的老客戶可以使用新服務。這被設置爲默認的受Silverlight啓用WCF Web服務綁定,是一個標準Web服務通信的風格結合。這並不支持可靠的消息。

在下文中介紹的代碼片段,描繪的默認設置基礎綁定。

<binding name="basicHttpBindingDefaults" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxReceivedMessageSize="65536" messageEncoding="Text" proxyAddress="" textEncoding="utf-8" transferMode="Buffer" useDefaultWebProxy="true" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> <readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192"/> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> <message algorithmSuite="Basic256" clientCredentialType="UserName" />

上面的默認設置有其明顯的侷限性郵件大小是有限的,在這裏安全模式也無法比擬。但是基本的結合解決了這個問題類似下面的定製。

<binding name="basicHttpSecure" maxBufferSize="100000" maxReceivedMessageSize="100000"> <readerQuotas maxArrayLength="100000" maxStringContentLength="100000"/> <security mode="TransportWithMessageCredential" />

Web服務(WS)綁定

這是通過WSHttpBinding類提供,此綁定相似於基礎約束,並使用相同的協議進行傳輸,但提供了幾個WS- *規範,比如WS- 可靠消息,WS- 事務,WS- 安全,還有更多。簡而言之,WsHttpBinding等於總結basicHttpBinding和WS- *規範。在這裏,在下文中介紹的代碼片段,說明默認設置WS綁定。

<binding name="wsHttpBindingDefaults" allowCookies="false" bypassProxyOnLocal="false" closeTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" openTimeout="00:01:00" receiveTimeout="00:10:00" proxyAddress="" sendTimeout="00:01:00" textEncoding="utf-8" transactionFlow="false" useDefaultWebProxy="true" > <readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192"/> <reliableSession enabled="false" ordered="true" inactivityTimeout="oo:10:00" /> <security mode="Message"> <message algorithmSuite="Basic256" clientCredentialType="Windows" esatalishSecurityContext="true" negotiateServiceCredential="true" /> <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>

IPC綁定

這種結合使得使用命名管道,由netNamedPipeBinding類提供。這是最快的約束和所有可用的綁定是最安全的。雖然,消息級安全性這裏不支持,消息是因爲一個強大的運輸保障的默認安全。在這裏,下面的代碼片段,說明默認設置爲IPC結合。

<binding name="netPipeDefaults" closeTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transactionProtocol="OleTransactions" transferMode="Buffered" > <readerQuotas maxArrayLength="16384" maxBytesPerRead="4096" maxDepth="32" maxNameTableCharCount="16384" maxStringContentLength="8192"/> <security mode="Transport">

其他類型的服務綁定如下:

  • TCP Binding - 由NetTcpBinding類結合TCP協議的通信在同一網絡內,並且不會以二進制格式信息編碼。這種結合被認爲是最可靠的對比。

  • WS Dual Binding - 這種結合便於雙向通信,即消息可以被髮送和接收的客戶端和服務的唯一例外的是wsHttpBinding。這是由WSDualHttpBinding類提供的。

  • Web binding - 這種結合被設計爲表示WCF服務中的HTTP請求的形式,通過使用HTTP的GET和HTTP的POST等方式,這是可用的WebHttpBinding類,並與社會網絡常用。

  • MSMQ Binding - 這個綁定由NetMsmqBinding類,還提供用於提供在情況下,服務於一個不同於客戶端發送的處理消息時間的解決方案。這種結合使得使用MSMQ傳輸,並提供支持的消息隊列。 MSMQ是微軟提供的隊列消息實現。

  • Federated WS Binding - 這種結合是由WSFederationHttpBinding類提供。這是WS結合的一種具體形式,並提供支持,以聯合安全。

  • Peer Network Binding - 由NetPeerTCPBinding類提供,該結合主要是用在文件共享系統,例如種子和TCP協議中使用。它使用TCP協議等網絡運輸。在這個網絡中每個機器(節點)充當客戶端和一個服務器到另一個節點。這是用在像奔流的文件共享系統。

  • MSMQ Integration binding - 這種結合是由MsmqIntegrationBinding類提供的。這種結合提供支持MSMQ(微軟消息隊列),使現有通信系統進行通信。

除了這些,還可以創建自定義綁定。然而,由於它能夠調整每個WCF配置屬性綁定,需要創建自定義綁定的產生極少。