[英]WCF Service calls always fail after 30 seconds with (502) Bad Gateway
我們有一個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服務之間的問題。
您可能希望嘗試修改其他超時配置值:
closeTimeout,openTimeout,recieveTimeout。
有關配置項的信息,請參閱此MSDN帖子 ,摘要如下:
客戶端:
- SendTimeout用於初始化OperationTimeout,它控制發送消息的整個交互(包括在請求 - 回復情況下接收回復消息)。 從CallbackContract方法發送回復消息時,此超時也適用。
- 打開和關閉通道時使用OpenTimeout和CloseTimeout(當沒有傳遞顯式超時值時)。
服務器端:
- 發送,打開和關閉超時與客戶端(用於回調)相同。
- ServiceFramework層使用ReceiveTimeout初始化會話空閑超時。
添加:
我可以建議的唯一另一件事是使用WCF服務跟蹤查看器來找到導致問題的底部。 如果您需要有關如何使用它的詳細信息,請參閱此SO帖子 。
IIS - >高級設置 - >連接限制
將該數量(以秒為單位)增加到所需的數量。
希望這可以幫助任何Google員工!
我今天自己就遇到了這個問題。 從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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.