我发现自己需要找到使用 HTTPS/SOAP 并且必须是双工的 WCF 绑定(bind)。我之前以编程方式使用 NetTcpBinding,但现在绑定(bind)必须是 HTTPS/SOAP。我做了一些研究,看来如果不创建自己的 CustomBinding 是不可能的。
但是我有点不知所措(对绑定(bind)和设置不太熟悉)。我似乎无法获得所需的正确绑定(bind)元素:
public class CustomHttpsBinding : CustomBinding
{
public CustomHttpsBinding()
{
}
public override BindingElementCollection CreateBindingElements()
{
ReliableSessionBindingElement https = new ReliableSessionBindingElement();
SecurityBindingElement security = SecurityBindingElement.CreateCertificateOverTransportBindingElement();
CompositeDuplexBindingElement duplex = new CompositeDuplexBindingElement();
SslStreamSecurityBindingElement ssl = new SslStreamSecurityBindingElement();
MessageEncodingBindingElement encoding = new GZipMessageEncodingBindingElement((MessageEncodingBindingElement) new BinaryMessageEncodingBindingElement());
HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
return new BindingElementCollection(new BindingElement[] { https, security, duplex, ssl, encoding, transport });
}
在检查 SOAP 是否符合安全传输要求时,它给了我一个无效的操作异常,说我的契约(Contract)配置了需要完整性和 secret 性的身份验证模式。然而,传输无法提供完整性和 secret 性。
好像我的 HttpsTransportBindingElement 不正确?我不确定。
谢谢
编辑:
我确实曾经设法让 WSDualHttpBinding 工作,但似乎 HTTPS 无法使用它(以及互联网上的其他人说它甚至不应该使用)
最佳答案
HTTP 不是双工协议(protocol) - 它的请求/响应 - 这就是 wsDualHttpBinding 使用两个连接的原因 - 每个方向一个。 Silverlight 通过在后台轮询来自客户端的消息来实现 HTTP 上的双工
NetTcpBinding 使用 TCP,它可以很高兴地实现双工
如果您可以等到今年晚些时候发布 4.5,这里有 NetHttpBinding,它使用 WebSocket 协议(protocol)进行双工
关于c# - WCF 与 SOAP HTTPS 和双工绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10643463/