WCF服务绑定

WCF服务绑定是一个集合,每个元素定义了服务与客户端进行通信方式的几个元素。传输元素和一个消息编码元素各自结合两个最重要的组成部分。这里是WCF服务绑定常用的列表。

基础绑定

基础约束是由basicHttpBinding的类提供的,这种结合使用HTTP协议进行传输为目的,并代表一个WCF服务作为一个ASP.NET Web服务(ASMX Web服务),这样方便ASMX Web服务的老客户可以使用新服务。这被设置为默认的受Silverlight启用WCF Web服务绑定,是一个标准Web服务通信的风格结合。这并不支持可靠的消息。

在下文中介绍的代码片段,描绘的默认设置基础绑定。

<basicHttpBinding>
  <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" />
        </security>       
  </binding>
</basicHttpBinding>  
上面的默认设置有其明显的局限性邮件大小是有限的,在这里安全模式也无法比拟。但是基本的结合解决了这个问题类似下面的定制。

<basicHttpBinding>
  <binding name="basicHttpSecure" maxBufferSize="100000"
	 maxReceivedMessageSize="100000">
	 <readerQuotas maxArrayLength="100000" maxStringContentLength="100000"/>
     <security mode="TransportWithMessageCredential" />
  </binding>
</basicHttpBinding>
Web服务(WS)绑定

这是通过WSHttpBinding类提供,此绑定相似于基础约束,并使用相同的协议进行传输,但提供了几个WS- *规范,比如WS- 可靠消息,WS- 事务,WS- 安全,还有更多。简而言之,WsHttpBinding等于总结basicHttpBinding和WS- *规范。在这里,在下文中介绍的代码片段,说明默认设置WS绑定。

<wsHttpBinding>
  <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=""/>        	
        </security>
  </binding>
</wsHttpBinding>

IPC绑定

这种结合使得使用命名管道,由netNamedPipeBinding类提供。这是最快的约束和所有可用的绑定是最安全的。虽然,消息级安全性这里不支持,消息是因为一个强大的运输保障的默认安全。在这里,下面的代码片段,说明默认设置为IPC结合。

<netNamedPipeBinding>
  <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">        	
        </security>
  </binding>
</netNamedPipeBinding>
其他类型的服务绑定如下:
  • 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配置属性绑定,需要创建自定义绑定的产生极少。

联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2022

备案号:京ICP备15003423号-3