考虑到它们之间在安全设置方面的相关性,在这里我们先来介绍WSDualHttpBinding。 所以WSDualHttpBinding只能提供基于Message安全模式的支持。 这样的限制直接反映应用编程接口的定义上。 这也印证了关于WSDualHttpBinding不能够提供针对Transport安全的论点。在默认的情况下,WSDualHttpBinding采用Message安全模式。 其中Windows为默认的选项,意味着在默认情况下WSDualHttpBinding以Windows认证的方式实现对客户端的认证。 WSDualHttpBinding安全相关的应用编程接口的定义体现在如下所示的代码片断中。
BasicHttpBinding WSHttpBinding WSDualHttpBinding NetNamedPipeBinding NetTcpBinding NetMsmqBinding None Transport; 除了NetNamedPipeBinding,所有的绑定都支持Message安全模式; 对于所有支持Message模式的绑定,除了NetMsmqBinding都支持Mixed模式; 除了WSDualHttpBinding BasicHttpBinding WSHttpBinding WSDualHttpBinding NetNamedPipeBinding NetTcpBinding NetMsmqBinding None Yes - No No No Certificate Yes Yes - No Yes No 从下面的表格反映的数据我们可以看出: 三种基于HTTP的绑定(不包括不支持Transport安全模式的WSDualHttpBinding BasicHttpBinding WSHttpBinding WSDualHttpBinding NetNamedPipeBinding NetTcpBinding NetMsmqBinding None
运行到 ILogService service = DuplexChannelFactory<ILogService>.CreateChannel(client, new WSDualHttpBinding 当我们用WSDualHttpBinding进行双工通信时 在默认情况下,回调接口会使用80端口,clientBaseAddress为http://localhost:80 而80端口已经被IE浏览器占用 DuplexChannelFactory<ILogService> channelFactory = new DuplexChannelFactory<ILogService>(instanceContext); WSDualHttpBinding ws = new WSDualHttpBinding(); ws.ClientBaseAddress = new Uri("http://localhost:8566"); channelFactory.Endpoint.Binding EndpointAddress("http://localhost:8567/server"); ILogService service = channelFactory.CreateChannel(); 2修改配置文件 <wsDualHttpBinding
而WCF通过WSDualHttpBinding实现的双工通信机制和NetTcpBinding支持的双工通信具有本质的区别。 NetTcpBinding创建的传输通道就是一个双工的TCP连接,而WSDualHttpBinding创建的所谓的双工通道实际上是两个方向相反的HTTP连接。 WSDualHttpBinding 如果采用WSHttpBinding,最终创建的是一条从客户端到服务端的HTTP通道。 但是,如果我们采用WSDualHttpBinding作为终结点绑定,情况就大不一样了。 图2 可靠会话基于通过WSDualHttpBinding创建的双通道的消息交换 我们也可以从另外一种视角来看WSHttpBinding和WSDualHttpBinding对可靠会话的不同实现方式。
三、 WsDualHttpBinding 在前面对消息交换模式的介绍中,我们谈到三种典型的消息交换模式:单向的数据报模式、请求/回复模式和双工模式。 WsDualHttpBinding就是专门为HTTP传输下双工消息交换模式设计的。 binding = new WSDualHttpBinding(); 6: ListAllBindingElements(binding); 7: } 8: ,WsHttpbing并没有ReliableSessionBindingElement,也就是说在默认的情况下,WsHttpbing并不支持可靠会话,而对于基于双工通信的WsDualHttpBinding 答案很简单,WsDualHttpBinding采用了两个HTTP通道。 四、NetTcpBinding 到此为止,我们一共介绍了三种类型的绑定。
下面的代码演示了WSHttpBindingBase(WSHttpBinding和WS2007HttpBinding的基类)和WSDualHttpBinding的ReliableSession属性的定义。 对于前面提到的若干支持可靠会话的系统绑定,除了WSDualHttpBinding的ReliableSession属性类型为ReliableSession外,其余的均为OptionalReliableSession 也就是我们不能关闭WSDualHttpBinding的可靠会话特性,它总是按照可靠会话的机制进行消息的交换。WCF之所以如此涉及,是源于WSDualHttpBinding支持双工通信的特殊机制决定的。 也就是说,对于通过WSDualHttpBinding创建的所谓的双工通道是由两个方向相反的HTTP连接组成的,WCF采用可靠会话机制提供对这两个连接的匹配。 我们可以通过编程的方式开启或者关闭终结点使用的除WSDualHttpBinding之外的其他系统绑定(限于支持可靠会话系统绑定)的可靠会话开关,以及设置InactivityTimeout和Ordered
ws2007HttpBinding> 一个安全且可互操作的绑定,可为Security,ReliableSession的正确版本和TransactionFlow绑定元素提供支持 HTTP/HTTPS Text,MTOM WSDualHttpBinding <wsDualHttpBinding> 一个安全且可互操作的绑定,适用于双工服务协定或通过SOAP媒介进行的通信 HTTP Text,MTOM WSFederationHttpBinding <wsFederationHttpBinding WS*事务支持 持久可靠消息传送 可靠会话 性能 请求/响应 单向 双工 basicHttpBing √ √ √ 良好 √ √ wsHttpBinding √ √ √ √ √ 良好 √ √ wsDualHttpBinding
目录 一、BasicHttpBinding 二、WSHttpBinding、WS2007HttpBinding和WSDualHttpBinding 三、 所以我们仅仅分析WS2007HttpBinding和WSDualHttpBinding。 接着来看用户双向通信的WSDualHttpBinding。通过前面的接收,我们已经知道了该邦绑定仅仅支持Message安全模式。 我们同样调用ListAllBindingElements扩展方法列出WSDualHttpBinding在Message安全模式下的所有绑定元素。 1: WSDualHttpBinding binding = new WSDualHttpBinding(WSDualHttpSecurityMode.Message); 2: Console.WriteLine
WSDualHttpBinding是基于HTTP传输协议的;而HTTP协议本身是基于请求-回复的传输协议,基于HTTP的通道本质上都是单向的。 WSDualHttpBinding实际上创建了两个通道,一个用于客户端向服务端的通信,而另一个则用于服务端到客户端的通信,从而间接地提供了双工通信的实现。 现在我们采用基于HTTP的WSDualHttpBinding看看我们的应用能否正常运行。我们需要做的仅仅是改变服务端和客户端的配置。 1: <? 图6 II 5.x + WsDualHttpBinding导致的AddressAlreadyInUseException异常 该异常的出现和不同版本的IIS监听机制有关。 WsDualHttpBinding定义了一个ClientBaseAddress使你能很容易地改变回调服务的基地址。
由于双工通信依赖于一个双工的信道栈,即依赖于一个能够支持双工通信的绑定,在此我们选用了NetTcpBinding,Mono下的wsDualHttpBinding 是不支持的哦,具体可以参看 http:/ supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> 注: 在WCF预定义绑定类型中,WSDualHttpBinding WSDualHttpBinding是基于HTTP传输协议的;而HTTP协议本身是基于请求-回复的传输协议,基于HTTP的通道本质上都是单向的。 WSDualHttpBinding实际上创建了两个通道,一个用于客户端向服务端的通信,而另一个则用于服务端到客户端的通信,从而间接地提供了双工通信的实现。
配置预定义绑定类型 在WCF预定义绑定类型中,WSDualHttpBinding和NetTcpBinding均提供了对双工通信的支持,但是两者在对双工通信的实现机制上却有本质的区别。 WSDualHttpBinding是基于HTTP传输协议的;而HTTP协议本身是基于请求-回复的传输协议,基于HTTP的通道本质上都是单向的。 WSDualHttpBinding实际上创建了两个通道,一个用于客户端向服务端的通信,而另一个则用于服务端到客户端的通信,从而间接地提供了双工通信的实现。 CalculatorService/" /> </baseAddresses> </host> </service> 我们现在暂时就用wsDualHttpBinding
而WCF通过WSDualHttpBinding实现的双工通信机制和NetTcpBinding支持的双工通信具有本质的区别。 NetTcpBinding创建的传输通道就是一个双工的TCP连接,而WSDualHttpBinding创建的所谓的双工通道实际上是两个方向相反的HTTP连接。 接下来我们主要讨论当我们采用基于HTTP绑定——WSHttpBinding(或者是 WS2007HttpBinding)和WSDualHttpBinding)时,实现可靠会话所进行的通信方式… 阅读全文
PrintTransactionFlowSupport(new WS2007HttpBinding()); 13: PrintTransactionFlowSupport(new WSDualHttpBinding No WSHttpBinding Yes WS2007HttpBinding Yes WSDualHttpBinding TransactionProtocol { get; set; } 13: } 而对于基于WS的绑定来说,由于绑定本身就是为跨平台和互操作涉及的,所以仅仅支持基于WS-AT的事务处理协议,其中WSHttpBinding、WSDualHttpBinding
可是系统提供的WSDualHttpBinding也是支持双工的,但是它的通道是无状态的Http协议 另外对于多个服务操作调用,有时我们需要它们之间有一些状态共用,那么也需要有一个方式将一系列消息关联在一起
WCF通过WsDualHttpBinding实现了基于HTTP协议的双工通信,实际上是采用了两个HTTP通道实现的。
在前面两篇(《绑定、安全模式与客户端凭证类型:BasicHttpBinding》和《绑定、安全模式与客户端凭证类型:WSHttpBinding与WSDualHttpBinding》)中,我们详细地介绍了四种基于
WSDualHttpBinding: 和 WSHttpBinding 相比,它支持 duplex 类型的服务。
181 //Binding 182 System.ServiceModel.Channels.Binding binding = new WSDualHttpBinding ; 184 ((System.ServiceModel.WSDualHttpBinding)(binding)).Security.Message.ClientCredentialType , myEp); 197 //executeServiceClient = new ExecuteServiceClient(instanceContext, new WSDualHttpBinding (), ""); 150 151 System.ServiceModel.Channels.Binding binding = new WSDualHttpBinding ; 153 ((System.ServiceModel.WSDualHttpBinding)(binding)).Security.Message.ClientCredentialType
绑定:WCF支持多种类型,如 basicHttpBinding,WSDualHttpBinding,WSHttpBinding等绑定,而Web服务仅支持SOAP或XML。
对于所有支持Message模式的绑定来说,只有基于WS的绑定(WSHttpBinding、WS2007HttpBinding和WSDualHttpBinding)支持服务凭证协商。 calculator.Add(1, 2); 19: ... 20: } 我们当然还是推荐采用配置的方式来控制服务凭证协商,在WSHttpBinding、WS2007HttpBinding和WSDualHttpBinding