当前位置: 代码迷 >> C# >> 100分求解,在win2003系统中使用WCF,出现套接字连接已中止。解决方法
  详细解决方案

100分求解,在win2003系统中使用WCF,出现套接字连接已中止。解决方法

热度:48   发布时间:2016-05-05 02:40:34.0
100分求解,在win2003系统中使用WCF,出现套接字连接已中止。
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;
                    }

------解决思路----------------------
 我是来接分滴
------解决思路----------------------
这不是提示超时了吗,1分29秒多超时的。
------解决思路----------------------
检查下你要访问的端口是不是能连接。允许连接了才可以。
------解决思路----------------------
能调试吗?单步调试下到底哪有问题
------解决思路----------------------
WCF的报错有时候很不靠谱。
你检查一下你传输的对象以及它的属性是否有空值,特别是枚举是否有赋值。
把这些空值都赋一个默认值试试。
------解决思路----------------------
在你的服务类头上添加[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
将一般性的服务端错误返回给客户端,这样你客户端就知道是什么错误了,现在这情况是被你屏蔽了错误,所以根本无法分析错误原因。
------解决思路----------------------
  相关解决方案