We keep getting the following error when we try through ews to get emails from different exchange
mailboxes. As soon as we restart the application, or even without restarting it sometimes everything gets back to normal.
The request failed. The underlying connection was closed: An unexpected error occurred on a send. at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.FindItems(FolderId parentFolderId, SearchFilter searchFilter, ViewBase view)
We have in total 25 threads. On Each thread we get messages from a certain number of mailboxes (between 5 and 25 ).
We try to get the emails since the last email received. Every minute we make a new request to get emails for all the mailboxes interrogated on a certain thread. Sometimes it takes more than one minute to query all the mailboxes associated to one thread. If this is happening than the next request comes immediately after.
Each time before requesting for new emails we create a new ExchangeService object in the following way:
this.exchangeService = new ExchangeService(connectionInfo.ExchangeVersion);
this.exchangeService.Credentials = new NetworkCredential(connectionInfo.User, connectionInfo.Password, connectionInfo.Domain);
this.exchangeService.Url = new Uri(connInfo.Url);
this.exchangeService.Timeout = 300000; // 5 min
this.exchangeService.TraceListener = new ExchangeTraceListener();
this.exchangeService.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse; // trace both request and response
this.exchangeService.TraceEnabled = true;
//Connections with same Group name are processed in one thread
if (!Guid.Empty.Equals(connectionGroupName)) exchangeService.ConnectionGroupName = connectionGroupName.ToString();
For each thread we have a distinct ConnectionGroupName.
Once The exchangeservice object is created we get all the items received at the exchange side since the last email was picked up.
ItemView iview = new ItemView(synchronizedCount);
iview.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.DateTimeReceived);
iview.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
FindItemsResults<Item> findResults = exchangeService.FindItems(xsFolder.XsFolderId, new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived,startDateTime),iview);
For each item in the list we load the following properties:
PropertySet propertySet = new PropertySet();
propertySet.Add(ItemSchema.MimeContent);
propertySet.Add(ItemSchema.DateTimeReceived);
propertySet.Add(ItemSchema.HasAttachments);
exchangeService.LoadPropertiesForItems(itemList, propertySet);
If you need any other information or clarification please let me know.
Thank you.
We would like to get concrete help in solving the problem. If for this is necessary to pay is fine for us. Just please inform us how we should proceed.
- Moved by Fei XueMicrosoft contingent staff 5 hours 51 minutes ago