我有一个托管在AWS上的WCF应用程序。为了实现更高的可用性,我创建了WCF计算机的快照,并使用此映像启动了另一个实例。
此外,我创建了一个Elastic Load Balance(ELB),可以将请求路由到这两个服务器。
使用我的WCF客户端,如果我使用机器公共IP地址,我可以成功连接两台服务器。 但是如果我使用ELB主机名,我的连接将失败,并显示以下错误:
System.ServiceModel.FaultException:消息不能 处理。这很可能是因为这个动作 “http://tempuri.org/IService/GetCustomerData”不正确或因为 消息包含无效或过期的安全上下文令牌或 因为绑定之间存在不匹配。安全上下文 如果服务中止了该通道,则令牌将无效 闲置。防止服务中止空闲会话 过早增加服务端点上的接收超时 结合。
该错误表明我的安全令牌无效或已过期。所以,我已经检查了发送和接收超时,它已经设置为10分钟:sendTimeout="00:10:00"
,receiveTimeout="00:10:00"
(请求通常需要5-15秒)
我的招架配置:
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" useDefaultWebProxy="true">
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Basic"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
另外,我已经仔细检查了一下:
答案 0 :(得分:9)
我设法解决了这个问题,添加了以下参数:establishSecurityContext="false"
。
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" useDefaultWebProxy="true">
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Basic"/>
<message clientCredentialType="UserName"
establishSecurityContext="false"/> <!-- this line -->
</security>
</binding>
</wsHttpBinding>
</bindings>
谷歌搜索,我已经了解到:
当此值设置为 false 时,必须使用非对称加密进行密钥交换和验证。此参数的默认值为 true ,这意味着第一次调用将创建具有非对称加密的安全上下文,但它将被缓存,而其他调用将仅使用对称加密,这会更快。 / p>
绩效考虑:Yaron Naveh
当预计客户端会连续拨打多个电话时,最好将此参数设置为 true ,但是使用负载均衡,将呼叫路由到不同的服务器,这会中断由于令牌无效而导致的消息。因此,您必须禁用此安全上下文功能。
建立安全上下文部分中的详细说明:https://msdn.microsoft.com/en-us/library/hh273122(v=vs.100).aspx
答案 1 :(得分:1)
根据您在ELB上安装了正确证书的声明,我假设您正在使用SSL卸载。这可能是一个问题,因为客户端绑定需要使用传输安全性进行配置,但服务将通过端口80接收请求,因此需要不同的绑定配置。
但是,在指定客户端凭据时,WCF需要传输安全性,因此如果需要发送客户端凭据,则可能必须关闭SSL卸载。