win2003系统中使用WCF,出现套接字连接已中止。

.Net技术 码拜 9年前 (2015-10-13) 1150次浏览
RT,系统是windows 2003 ,服务器端是web,客户端是winform,不使用服务引用,服务器端打开wcf服务正常的情况下,客户端去连接服务器端出现:套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或潜在的网络资源问题导致的。本地套接字超时是“00:01:29.9709963”。在本机的WIN7和XP 系统测试没有问题,想问一下各位一般出现这个异常要怎么样解决?附上WCF配置代码:

服务器:

NetTcpBinding myBinding = new NetTcpBinding();
                myBinding.Security.Mode = SecurityMode.None;
                myBinding.MaxReceivedMessageSize = 2147483647;
                myBinding.TransferMode = TransferMode.Streamed;
                myBinding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
                myBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                myBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                Uri baseAddress = new Uri("net.tcp://" + ip + ":9999/WCFService/");
                myServiceHost = new ServiceHost(typeof(Service), baseAddress);
                ServiceEndpoint myServiceEndpoint = myServiceHost.AddServiceEndpoint
                    (typeof(IService), myBinding, "GetIdentity");
                try
                {
                    myServiceHost.Open();
                    if (myServiceHost.State == CommunicationState.Opened)
                        return true;
                    else
                        return false;
                }
                catch (Exception ex)
                {
                    throw ex;
                }

客户端:

                    
                    NetTcpBinding binding = new NetTcpBinding();
                    binding.Security.Mode = SecurityMode.None;
                    binding.TransferMode = TransferMode.Streamed;
                    binding.MaxBufferPoolSize = int.MaxValue;
                    binding.MaxBufferSize = int.MaxValue;
                    binding.MaxReceivedMessageSize = 2147483647;
                    binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas();
                    binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                    binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                    binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                    binding.OpenTimeout = new TimeSpan(0, 1, 30);
                    binding.ReceiveTimeout = new TimeSpan(0, 1, 30);
                    binding.SendTimeout = new TimeSpan(0, 1, 30);
                    //利用通道创建客户端代理
                    DCF = new ChannelFactory<IService>(binding, new EndpointAddress("net.tcp://" + ip + ":9999/WCFService/GetIdentity"));
                    _proxy = DCF.CreateChannel();
                    IContextChannel obj = _proxy as IContextChannel;//订阅消息
                    try
                    {
                        _proxy.isOnline();
                        isok = true;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
解决方案:2分
这不是提示超时了吗,1分29秒多超时的。
解决方案:25分
检查下你要访问的端口是不是能连接。允许连接了才可以。
解决方案:30分
能调试吗?单步调试下到底哪有问题
解决方案:10分
WCF的报错有时候很不靠谱。

你检查一下你传输的对象以及它的属性能否有空值,特别是枚举能否有赋值。

把这些空值都赋一个默认值试试。

解决方案:30分
在你的服务类头上添加[ServiceBehavior(IncludeExceptionDetailInFaults = true)]

将一般性的服务端错误返回给客户端,这样你客户端就知道是什么错误了,现在这情况是被你屏蔽了错误,所以根本无法分析错误原因。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明win2003系统中使用WCF,出现套接字连接已中止。
喜欢 (0)
[1034331897@qq.com]
分享 (0)