简体   繁体   中英

Increase timeout for waiting for a response from Exchange Web Server

I'm trying to move big bunch of messages to another folder and the operation take approximately 5-8 minutes depends of the servers' locations and amount of items to move. And I always get an error (504) Gateway Timeout , with the stack trace:

Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (504) Gateway Timeout. ---> System.Net.WebException: The remote server returned an error: (504) Gateway Timeout.
   at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
   --- End of inner exception stack trace ---
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request)
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalMoveItems(IEnumerable`1 itemIds, FolderId destinationFolderId, Nullable`1 returnNewItemIds, ServiceErrorHandling errorHandling)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.MoveItems(IEnumerable`1 itemIds, FolderId destinationFolderId)
   at EAS.Exchange.ExchangeProvider.MoveItemsToFolder(String folderUniqueId, String[] itemUniqueIds)

I was trying to increase timeout for ExchangeService :

var ews = new Microsoft.Exchange.WebServices.Data.ExchangeService();
ews.Timeout = 900000; // 15 minutes in milliseconds

but it doesn't solve the problem. By the way, the operation finishes successfully on the EWS and all the items are moved after that.

Could you please recommend another possible solution how to fix this issue?

The 504 error indicates that the remote server experienced a timeout. If you experienced a direct timeout, after all, then nothing would have had a chance to send back an HTTP status code.

So the issue is not due to the connection between your program and the Exchange service; the problem is due to one of the following:

  1. A connection is timing out between the Exchange service and some other service that Exchange uses internally. You will need to figure out which component is timing out and adjust the timeout settings specific to that area of the system. There are a lot of timeouts to look at. You could start here .

  2. Your access to the Exchange service is mediated by a proxy server, and the connection between the proxy server and Exchange is timing out. You may need to adjust the proxy server settings.

You may be able to determine which of the above is the issue by inspecting the W3C logs and searching for 504s. Or you may be able to tell what a 504 looks like when it comes from the proxy simply by its styling, depending on how you have things set up. Another possibility is to add the Exchange server's address to your proxy exclusion list and see if that has any effect.

The error may be caused by the Connection Time-out value set in IIS.

Try increasing the value:

IIS -> Right-click your application -> Manage Website -> Advanced Settings -> Expand Limits -> Increase Connection Time-out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM