繁体   English   中英

使用(502)Bad Gateway后,WCF服务调用在30秒后始终失败

[英]WCF Service calls always fail after 30 seconds with (502) Bad Gateway

我们有一个WCF服务(BasicHttpBinding),它将在30秒后始终失败。 30秒内的通话完成且没有错误。 超过30秒的任何事情都会因502 Bad Gateway异常而失败:

System.Net.WebException:远程服务器返回错误:(502)Bad Gateway。

但是WCF调用继续在后台运行(并最终完成)。 我们已经确认BasicHttpBinding - Binding - sendTimeout(在web.config中)大于30秒(实际设置为5分钟)。 我们在客户端和服务器上都证实了这一点。

这是完整的堆栈跟踪:

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (502) Bad Gateway. ---> System.Net.WebException: The remote server returned an error: (502) Bad Gateway.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, 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)

这30秒“超时”的来源或为什么会返回502 Bad Gateway错误?

解决方案:我们使用的IIS7应用程序请求路由模块具有自己的代理设置。 代理设置的默认超时为30秒。 将此增加到600秒(10分钟)解决了我们的问题。 Bad Gateway错误并不完全正确,但WCF跟踪查看器(请参阅答案)帮助确定问题不是服务本身,而是客户端和wcf服务之间的问题。

您可能希望尝试修改其他超时配置值:

closeTimeout,openTimeout,recieveTimeout。

有关配置项的信息,请参阅此MSDN帖子 ,摘要如下:

客户端:

  • SendTimeout用于初始化OperationTimeout,它控制发送消息的整个交互(包括在请求 - 回复情况下接收回复消息)。 从CallbackContract方法发送回复消息时,此超时也适用。
  • 打开和关闭通道时使用OpenTimeout和CloseTimeout(当没有传递显式超时值时)。

服务器端:

  • 发送,打开和关闭超时与客户端(用于回调)相同。
  • ServiceFramework层使用ReceiveTimeout初始化会话空闲超时。

添加:

我可以建议的唯一另一件事是使用WCF服务跟踪查看器来找到导致问题的底部。 如果您需要有关如何使用它的详细信息,请参阅此SO帖子

IIS - >高级设置 - >连接限制

将该数量(以秒为单位)增加到所需的数量。

希望这可以帮助任何Google员工!

我今天自己就遇到了这个问题。 从SL4应用程序将文件上载到WCF Web服务,在30秒后不断引发ConnectionTimeout异常。

我发现问题的原因是使用Microsoft建议的WebRequest.RegisterPrefix方法来克服Silverlight中的错误异常处理:

bool registerResult = WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);

请参阅http://msdn.microsoft.com/en-us/library/ee844556(v=vs.95).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM