简体   繁体   English

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

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

We have a WCF service (BasicHttpBinding) which will always fail after 30 seconds. 我们有一个WCF服务(BasicHttpBinding),它将在30秒后始终失败。 Calls under 30 seconds complete without error. 30秒内的通话完成且没有错误。 Anything over 30 seconds will fail with a 502 Bad Gateway exception: 超过30秒的任何事情都会因502 Bad Gateway异常而失败:

System.Net.WebException: The remote server returned an error: (502) Bad Gateway. System.Net.WebException:远程服务器返回错误:(502)Bad Gateway。

But yet the WCF call continues to run in the background (and will eventually complete). 但是WCF调用继续在后台运行(并最终完成)。 We have confirmed that the BasicHttpBinding - Binding - sendTimeout (in web.config) is greater than 30 seconds (actually set to 5 minutes). 我们已经确认BasicHttpBinding - Binding - sendTimeout(在web.config中)大于30秒(实际设置为5分钟)。 We confirmed this both on the client and the server. 我们在客户端和服务器上都证实了这一点。

Here is the full stack trace: 这是完整的堆栈跟踪:

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)

Any ideas where this 30 second "timeout" is coming from or why a 502 Bad Gateway error is returned? 这30秒“超时”的来源或为什么会返回502 Bad Gateway错误?

SOLUTION: We are using the IIS7 Application Request Routing Module which has Proxy settings of its own. 解决方案:我们使用的IIS7应用程序请求路由模块具有自己的代理设置。 The Proxy settings have a default timeout of 30 seconds. 代理设置的默认超时为30秒。 Increasing this to 600 seconds (10 minutes) solved our problem. 将此增加到600秒(10分钟)解决了我们的问题。 The Bad Gateway error is not completely correct but WCF Trace Viewer (see answer) helped see that the problem was not the service itself but an issue in between the client and the wcf service. Bad Gateway错误并不完全正确,但WCF跟踪查看器(请参阅答案)帮助确定问题不是服务本身,而是客户端和wcf服务之间的问题。

You may want to look try modifying the other timeout config values: 您可能希望尝试修改其他超时配置值:

closeTimeout, openTimeout, recieveTimeout. closeTimeout,openTimeout,recieveTimeout。

See this MSDN post for information on the config items, summary below: 有关配置项的信息,请参阅此MSDN帖子 ,摘要如下:

Client side: 客户端:

  • SendTimeout is used to initialize the OperationTimeout, which governs the whole interaction for sending a message (including receiving a reply message in a request-reply case). SendTimeout用于初始化OperationTimeout,它控制发送消息的整个交互(包括在请求 - 回复情况下接收回复消息)。 This timeout also applies when sending reply messages from a CallbackContract method. 从CallbackContract方法发送回复消息时,此超时也适用。
  • OpenTimeout and CloseTimeout are used when opening and closing channels (when no explicit timeout value is passed). 打开和关闭通道时使用OpenTimeout和CloseTimeout(当没有传递显式超时值时)。

Server side: 服务器端:

  • Send, Open, and Close Timeout same as on client (for Callbacks). 发送,打开和关闭超时与客户端(用于回调)相同。
  • ReceiveTimeout is used by ServiceFramework layer to initialize the session-idle timeout. ServiceFramework层使用ReceiveTimeout初始化会话空闲超时。

ADDED: 添加:

The only other thing I can suggest is to use the WCF Service Trace Viewer to get to the bottom of what's causing the issue. 我可以建议的唯一另一件事是使用WCF服务跟踪查看器来找到导致问题的底部。 See this SO Post if you require details on how to use it. 如果您需要有关如何使用它的详细信息,请参阅此SO帖子

IIS -> Advanced Settings -> Connection Limits IIS - >高级设置 - >连接限制

Increase that number (in seconds) to the desired amount. 将该数量(以秒为单位)增加到所需的数量。

Hope this helps any Googlers out there! 希望这可以帮助任何Google员工!

I've hit this very problem myself today. 我今天自己就遇到了这个问题。 Uploading a file to a WCF webservice from a SL4 app kept raising a ConnectionTimeout exception after 30secs. 从SL4应用程序将文件上载到WCF Web服务,在30秒后不断引发ConnectionTimeout异常。

I found the cause of the problem to be the use of the WebRequest.RegisterPrefix method as recommended by Microsoft to overcome Fault Exception handling in Silverlight: 我发现问题的原因是使用Microsoft建议的WebRequest.RegisterPrefix方法来克服Silverlight中的错误异常处理:

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

See http://msdn.microsoft.com/en-us/library/ee844556(v=vs.95).aspx 请参阅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