我有一个自托管的 C# WCF .Net 4.6.1 Windows 服务,它与另一个自托管的 WCF 服务通信。当两个服务都在同一台服务器上时,这可以正常工作。但是,当我将服务器移动到另一台计算机时,我收到此错误:
System.ServiceModel.CommunicationException:套接字连接已中止。这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题造成的。两台计算机上都没有运行防火墙,并且在使用http://192.168.1.129:6253/eTutorWcfService(在应用程序中使用 net.tcp)时得到响应。
客户app.config
:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IeTutorMessage" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IeTutorMessage" />
</netTcpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_IeTutorMessage"
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" />
<endpoint name="NetTcpBinding_IeTutorMessage"
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IeTutorMessage"
contract="eTutorServiceReference.IeTutorMessage" >
<identity>
<servicePrincipalName value = ""/>
</identity>
</endpoint>
</client>
服务器app.config
:
<services>
<service name="eTutorServer.eTutorWcfService"
behaviorConfiguration="myeTutorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:6253/eTutorWcfService"/>
<add baseAddress="net.tcp://localhost:6254/eTutorWcfService"/>
</baseAddresses>
</host>
<endpoint
address="http://localhost:6253/eTutorWcfService"
binding="basicHttpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="net.tcp://localhost:6254/eTutorWcfService"
binding="netTcpBinding"
contract="eTutorServer.IeTutorMessage" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myeTutorServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
客户端代码:
EndpointAddress address = new EndpointAddress("net.tcp://" + eTutorServiceIp + ":6254/eTutorWcfService");
eTutorServiceReference.IeTutorMessageClient client = new eTutorServiceReference.IeTutorMessageClient("NetTcpBinding_IeTutorMessage", address);
try
{
rtn = client.eTutorMessage(itm);
client.Close();
}
当客户端尝试连接时,服务器的输出窗口会显示一个SecurityTokenValidationException
但我不确定该怎么做,或者它是否意味着相关的东西。我确定这与安全性有关,但我不知道在哪里添加什么。