我天真地为1.1做了一个basicbinding,为1.2做了一个webhttbinding,并将它们作为端点添加到同一个主机
var basicBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
basicBinding.Security.Transport.ClientCredentialType = clientCredType;
s_serviceHost.AddServiceEndpoint(typeof(IFoo), basicBinding, "");
var httpBinding = new WebHttpBinding(WebHttpSecurityMode.Transport);
httpBinding.Security.Transport.ClientCredentialType = clientCredType;
var httpsEndpoint = s_serviceHost.AddServiceEndpoint(typeof(IFoo), httpBinding, "");
wcf对象说
If two endpoints want to share the same ListenUri, they must also share the same binding object instance.
The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.
编辑:也许我需要稍微改变一下措辞。同一个端点(比如mything.org/service)是否支持1.1和1.2 ?例如,通过简单地查看负载,wcf服务将决定如何读取它
当您通过ServiceHost
对象调用AddServiceEndpoint
时,您为地址参数指定了两次""
。这被解释为相对URI -相对于ServiceHost
的基址。所以在这种情况下两个端点的地址是相同的。
这本身不是问题,但当它们具有不同的绑定时(BasicHttpBinding
和WebHttpBinding
),它就变成了一个问题。
从MSDN上指定端点地址:
如果您有多个端点,每个端点都配置了一个不同的绑定,它们的地址必须是唯一的。端点使用相同的绑定但不同的合约可以使用相同的地址。
如果你对WCF中单个ListenUri
不能支持多个绑定的原因感兴趣。MSDN上单个ListenUri文章的多个端点状态:
…同一个ListenUri的端点必须有相同的绑定,因为它们共享一个通道堆栈来监听在机器上的物理地址的消息。
要解决这个问题,您需要为至少一个端点指定一个非空字符串。
s_serviceHost.AddServiceEndpoint(typeof(IFoo), httpBinding, "http");
与你的情况相关,但不是问题所在:
WebHttpBinding
是通过HTTP请求而不是基于soap的消息传递公开的Web服务的绑定。我相信您正在寻找支持SOAP 1.2的WSHttpBinding
。