TimoutException通过网络发生,但不在本地发生

时间:2010-03-24 16:02:53

标签: c# wcf timeoutexception

我有一个带有三个WCF服务的程序,当我在本地运行它们时(即:服务器和客户端都在localhost上)一切正常。但是,当我通过网络测试它时,我得到两个服务的TimoutException而不是另一个服务。我已经在测试中涉及的所有机器上禁用了防火墙。我可以ping服务器并从客户端访问wsdl“你已经创建了一个服务”网页

有效的服务使用BasicHttpBinding和流,两个不工作使用WSDualHttpBinding。使用WSDualHttpBinding的服务都有CallbackContracts。我为这个问题的模糊性道歉,但我不确定要包含哪些代码,或者甚至在哪里开始寻找解决方案。

非工作绑定:

public static Binding CreateHTTPBinding()
{
  var binding = new WSDualHttpBinding();

  binding.MessageEncoding = WSMessageEncoding.Mtom;

  binding.MaxBufferPoolSize = 2147483647;
  binding.MaxReceivedMessageSize = 2147483647;
  binding.Security.Mode = WSDualHttpSecurityMode.None;
  return binding;
}

异常堆栈跟踪:

Unhandled Exception: System.TimeoutException: The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.

Server stack trace:
   at System.ServiceModel.Channels.ReliableRequestor.ThrowTimeoutException()
   at System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IDemeService.Register()
   at DemeServiceClient.Register()
   at DemeClient.Client.Start()
   at DemeClient.Program.Main(String[] args)

2 个答案:

答案 0 :(得分:0)

您可以在两端启用System.Net跟踪并阅读有关超时异常的信息。

http://support.microsoft.com/kb/947285

答案 1 :(得分:0)

您正在使用DualHttpBinding。这意味着您正在设置双工通道,其中服务器可以向客户端发送消息(不是响应消息,而是传入消息)。但是您没有设置clientBaseAddress客户端将侦听来自服务器的传入消息。这就是造成这个问题的原因。来自http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx

此绑定要求客户端具有公共URI,该URI为服务提供回调端点。这是由ClientBaseAddress提供的。双重绑定将客户端的IP地址暴露给服务。客户端应使用安全性来确保它只连接到它信任的服务。