2010-05-04 122 views
6

我們有一個WCF服務(BasicHttpBinding),它在30秒後總是失敗。 30秒內通話完成,沒有錯誤。任何超過30秒就會失敗,一個502錯誤網關例外:WCF服務調用總是在30秒後失敗(502)Bad Gateway

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

但尚未WCF調用繼續在後臺運行(並最終完成)。我們已經確認BasicHttpBinding - 綁定 - 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錯誤網關錯誤任何想法?

解決方案: 我們正在使用具有自己的代理設置的IIS7應用程序請求路由模塊。代理服務器設置的默認超時時間爲30秒。將這個增加到600秒(10分鐘)解決了我們的問題。錯誤的網關錯誤並不完全正確,但WCF跟蹤查看器(請參閱答案)幫助瞭解問題不是服務本身,而是客戶端和wcf服務之間的問題。

回答

5

你可能想看看嘗試修改其它超時配置值:

closeTimeout,openTimeout,recieveTimeout。

上的配置項信息,請參閱this MSDN post,以下總結:

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). This timeout also applies when sending reply messages from a CallbackContract method.
  • OpenTimeout and CloseTimeout are used when opening and closing channels (when no explicit timeout value is passed).

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.

新增:

唯一的其他東西我可以建議是使用WCF服務跟蹤查看器去的底部是什麼導致了這個問題。如果您需要有關如何使用它的詳細信息,請參閱此SO Post

+0

我們已經嘗試增加closeTimeout,openTimeout和receiveTimeout到5分鐘(在客戶端和服務器上)並仍然看到問題。 – 2010-05-04 15:20:14

+0

感謝有關WCF服務跟蹤查看器的信息。我用它來收集客戶端和服務器上的跟蹤信息,但我從中看到服務器正在正常完成,但客戶端以「接收到錯誤的HTTP響應」結束,內部消息是「遠程服務器返回一個意外的迴應:(502)壞門戶。「服務器在42秒後完成,客戶端在31秒時收到錯誤。客戶端總是31秒。 – 2010-05-05 18:42:45

+0

想通了。我們使用具有代理設置的IIS7應用程序請求路由模塊,其中一個是30秒超時。使用WCF服務跟蹤查看器的確幫助我理解WCF服務不是問題,而是客戶端與服務之間的問題。 – 2010-05-05 20:07:16

0

我今天自己碰到這個問題。從SL4應用程序上傳文件到WCF Web服務在30secs之後不斷提高ConnectionTimeout異常。

我發現這個問題的原因是使用WebRequest.RegisterPrefix方法所推薦的微軟克服在Silverlight故障異常處理:

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

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

1

IIS - >高級設置 - >連接限制

將該數字(以秒爲單位)增加到所需的數量。

希望這可以幫助任何Google員工在那裏!