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;
}
附上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;
}
DataTable dt = new DataTable();
dt.TableName = "mrzhou";
binding.ReceiveTimeout = new TimeSpan(0, 1, 30);
binding.SendTimeout = new TimeSpan(0, 1, 30);这当中的事件调节的更长,客户端调试到_proxy.isOnline();就自动断开调试,也不会进入catch中
你检查一下你传输的对象以及它的属性是否有空值,特别是枚举是否有赋值。
把这些空值都赋一个默认值试试。
加个这个试试吧,我也不知道咋弄了
binding.CloseTimeout = new System.TimeSpan(0, 1, 30);
将一般性的服务端错误返回给客户端,这样你客户端就知道是什么错误了,现在这情况是被你屏蔽了错误,所以根本无法分析错误原因。