【发布时间】:2010-05-04 13:34:59
【问题描述】:
我们有一个 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 服务之间的问题。
【问题讨论】: