我的 WCF 服务在 Security Mode="Transport"和 clientCredentialType="Windows"下运行良好(客户端和服务在一台或两台机器上)。但是我需要将服务放在无法进行 Windows 身份验证的防火墙的另一端。我知道我可以安装 X.509 证书或使用 security="None"(我会添加我自己的安全协议(protocol))。但我无法让“无”工作!我不断收到“套接字连接已中止”错误。
这是配置,如果您发现任何问题,请告诉我。我在没有指定 clientCredentialType="none"的 2 行的情况下尝试过它,但它没有区别。附言每次我进行配置更改时,我都会停止并重新启动客户端和服务。
服务器配置
<system.serviceModel>
<services>
<service name="OuterService.OutCardTrx">
<endpoint address="" binding="netTcpBinding" contract="OuterService.IOutCardTrx">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://jimt4.campus.internal:8081/PCIOutService"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding">
<security mode="None" >
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
客户端配置:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IOutCardTrx" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://jimt4.campus.internal:8081/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IOutCardTrx" contract="OCS.IOutCardTrx"
name="NetTcpBinding_IOutCardTrx">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
最佳答案
不能 100% 确定这是原因,但您的绑定(bind)安全设置在客户端和服务之间不匹配。
请注意,NetTcpBinding 的默认安全性是Transport
(针对模式)。您在服务配置的绑定(bind)中定义了 None
,但该绑定(bind)从未分配给服务端点,因此您的服务正在使用 NetTcp 的默认设置。
另一方面,您正在客户端上设置绑定(bind)配置。
尝试在您的服务端点中设置绑定(bind)配置,如下所示:
<endpoint address="" binding="netTcpBinding"
bindingConfiguration="netTcpBinding"
contract="OuterService.IOutCardTrx">
这会将您指定的绑定(bind)分配给端点,安全设置为“无”。我还建议将绑定(bind)配置名称更改为“netTcpBinding”以外的名称,以避免任何可能的混淆。
关于安全模式为无的 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18622655/