我有一个先前配置为使用netttcp绑定的服务。
它的绑定是这样的:
<binding name="TcpBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Streamed" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288"
maxConnections="10" maxReceivedMessageSize="100000000">
<readerQuotas maxNameTableCharCount="1000000" maxStringContentLength="8192000"
maxArrayLength="1638400" />
<security mode="None"/>
</binding>
我试图将此转换为customBinding以启用leaseTimeout。
<customBinding>
<binding name="TcpBindingCustom" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" >
<windowsStreamSecurity protectionLevel="None" />
<transactionFlow transactionProtocol="OleTransactions"/>
<tcpTransport transferMode="Streamed" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" listenBacklog="10"
maxReceivedMessageSize="100000000" portSharingEnabled="true"
maxBufferSize="65536">
<connectionPoolSettings groupName="default" leaseTimeout="00:05:00"
idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" />
</tcpTransport>
</binding>
<customBinding>
我没有看到复制<security mode ="None">
的方法
当一切都在本地时,它运行得很好,但一旦部署,我就会得到以下异常:
System.ServiceModel.Security.SecurityNegotiationException:
The server has rejected the client credentials. --->
System.Security.Authentication.InvalidCredentialException:
The server has rejected the client credentials. --->
System.ComponentModel.Win32Exception:
使用tcpBinding没有得到这些错误。
如何使用customBinding复制此行为?是否有其他原因导致SecurityNegotiationException?
编辑:抱歉,我把配置块转过来了。WCF中的netttcpbinding是一个安全绑定,默认情况下使用Windows身份和传输安全性。尽管您正在尝试创建一个自定义版本,将安全模式设置为"none",但实际上您需要匹配netttcpbinding的配置方式。如果MSDN记录所有的标准绑定,并展示它们实际上是如何像自定义绑定那样的,那就太好了。试试这个配置:
<customBinding>
<binding name="TcpBindingCustom" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" >
<windowsStreamSecurity protectionLevel="None" />
<transactionFlow transactionProtocol="OleTransactions"/>
<tcpTransport transferMode="Streamed" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" listenBacklog="10"
maxReceivedMessageSize="100000000" portSharingEnabled="true"
maxBufferSize="65536">
<connectionPoolSettings groupName="default" leaseTimeout="00:05:00"
idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" />
</tcpTransport>
<security authenticationMode="AnonymousForSslNegotiated"/>
</binding>
<customBinding>
原来答案是从绑定标记中删除所有安全信息。在本例中,删除
<windowsStreamSecurity protectionLevel="None" />
和
<security authenticationMode="AnonymousForSslNegotiated"/>
我遵循了Sixto Saez的一些建议,并查看了Reflector中netttcpbinding的实现。
NetTcpBinding类重写CreateBindingElements方法以包含以下逻辑:
SecurityBindingElement item = this.CreateMessageSecurity();
if (item != null)
{
elements.Add(item);
}
与CreateMessageSecurity实现如下:
private SecurityBindingElement CreateMessageSecurity()
{
if ((this.security.Mode != SecurityMode.Message)
&& (this.security.Mode != SecurityMode.TransportWithMessageCredential))
{
return null;
}
return this.security.CreateMessageSecurity(this.ReliableSession.Enabled);
}
我的一个同事能够在调试器中逐步完成这个逻辑,并使用自定义绑定重现这个行为。
如果有人能生成一个转换表,显示如何使用自定义绑定元素创建基本绑定,那将非常有帮助。