套接字连接已中止。 WCF

时间:2019-08-23 04:52:59

标签: c# wcf windows-server-2012

连接到WCF服务时出现错误 它是一个有效的代码,我刚刚更改了服务器 窗口服务中托管的WCF服务 Windows服务正在运行

我有两个服务器 1. Windows Server 2012 R2 Standard的Server_1 2. Windows Server 2008 R2 Enterprise的Server_2

从Server_2呼叫正常 但是我从Server_1处遇到错误

套接字连接已中止。这可能是由于处理您的消息时出错,远程主机超出了接收超时或潜在的网络资源问题引起的。本地套接字超时为“ 00:30:00”。

8/23/2019 15:22:33 Process_Word_Document 8/23/2019 15:22:33 
 8/23/2019 15:22:33 szWord_Operation_Ip : 192.168.1.126
 8/23/2019 15:22:33net.tcp://192.168.1.126/CalcService
 8/23/2019 15:22:33 Channel 
 8/23/2019 15:22:33 eRROR : The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.9687487'. 8/23/2019 15:22:33 eRROR : Exception type System.ServiceModel.CommunicationException Exception message: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.9687487'. Stack trace: 
 ---BEGIN InnerException--- 
 Exception type System.Net.Sockets.SocketException
 Exception message: An existing connection was forcibly closed by the remote host
 Stack trace: at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
 at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
 ---END Inner Exception

选中Windows防火墙已关闭

NetTcpBinding _binding = new NetTcpBinding();
_binding.Security.Mode = SecurityMode.None;
_binding.SendTimeout = new TimeSpan(0, 10, 0);
_binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
_binding.OpenTimeout = new TimeSpan(0, 10, 0);
_binding.CloseTimeout = new TimeSpan(0, 10, 0);
 EndpointAddress _endpoint = new EndpointAddress("net.tcp://" + szWord_Operation_Ip + "/CalcService");
Channel = new ChannelFactory<Process_Word_Document.ICalcService>(_binding, _endpoint);
Process_Word_Document.ICalcService proxy = Channel.CreateChannel();
proxy.Update_Document_Properties(szFilePath);
Channel.Close();
Channel.Abort();
Channel = null;

1 个答案:

答案 0 :(得分:0)

您介意共享服务端吗?服务运行状态似乎有问题。请确保服务器端和客户端之间的绑定配置一致。我建议您使用WCFTestclient工具测试该服务是否有效。此外,请启用Windows功能以支持NetTCP协议。
enter image description here
enter image description here
最后,不要忘记服务地址包含端口号。

  

net.tcp://10.157.13.69:4386 / myservice

请随时告诉我是否有什么可以帮忙的。