我们有一个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服务之间的问题。
答案 0 :(得分:5)
您可能希望尝试修改其他超时配置值:
closeTimeout,openTimeout,recieveTimeout。
有关配置项的信息,请参阅this MSDN post,摘要如下:
客户方:
- SendTimeout用于初始化OperationTimeout,它控制发送消息的整个交互(包括 在请求 - 回复情况下接收回复消息)。这个超时也是 从CallbackContract方法发送回复消息时适用。
- 打开和关闭通道时使用OpenTimeout和CloseTimeout(当没有传递显式超时值时)。
服务器端:
- 发送,打开和关闭超时与客户端(用于回拨)相同。
- ServiceFramework层使用ReceiveTimeout来初始化会话空闲超时。
增加:
我可以建议的唯一另一件事是使用WCF服务跟踪查看器来了解造成问题的原因。如果您需要有关如何使用它的详细信息,请参阅此SO Post。
答案 1 :(得分:1)
IIS - >高级设置 - >连接限制
将该数字(以秒为单位)增加到所需的数量。
希望这可以帮助任何Google员工!
答案 2 :(得分:0)
我今天自己就遇到了这个问题。从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