WCF service calls always fail after 30 seconds with (502) Bad Gateway

We have a WCF service (BasicHttpBinding), which will always work after 30 seconds. Calls up to 30 seconds end without errors. All that in 30 seconds will fail with the exception of 502 Bad Gateway:

System.Net.WebException: The remote server returned an error: (502) Bad Gateway.

But the WCF call continues to run in the background (and will eventually complete). We have confirmed that BasicHttpBinding - Binding - sendTimeout (in web.config) is longer than 30 seconds (actually set to 5 minutes). We have confirmed this both on the client and on 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 that this 30 second timeout comes from, or why is the 502 Bad Gateway error returned?

SOLUTION: We use the IIS7 application request routing module, which has its own proxy settings. The proxy settings have a default timeout of 30 seconds. Increasing this to 600 seconds (10 minutes) solved our problem. The Bad Gateway error is not entirely correct, but the WCF trace viewer (see Answer) helped to understand that the problem is not in the service itself, but in the problem between the client and the wcf service.

+6
c # wcf
source share
3 answers

You can try to change other timeout configuration values:

closeTimeout, openTimeout, recieveTimeout.

See this MSDN post for information on configuration items, below:

Client side:

  • SendTimeout is used to initialize an OperationTimeout, which controls all communication to send a message (including receiving a response message in case of a response request). This timeout also applies when sending response messages from the CallbackContract method.
  • OpenTimeout and CloseTimeout are used when opening and closing channels (in the absence of an explicit timeout value).

Server side:

  • Postpone, open and close the timeout, as on the client (for callbacks).
  • ReceiveTimeout is used by the ServiceFramework layer to initialize the session timeout.

ADDED:

The only thing I can offer is to use the WCF service trace viewer to understand what is causing the problem. See the SOA post if you need information on how to use it.

+5
source share

IIS → Advanced Settings → Connection Restrictions

Increase this number (in seconds) to the desired amount.

Hope this helps any Googlers out there!

+1
source share

Today I myself ran into this problem. Uploading the file to the WCF web service from the SL4 application continued to raise ConnectionTimeout exception after 30 seconds.

I found the cause of the problem in using the WebRequest.RegisterPrefix method recommended by Microsoft for overcoming exception handling in Silverlight:

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

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

0
source share

All Articles