From time to time starting since 20 of February when we try to get emails from office 365 using ews the connection is blocked

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.ServiceRequestBase.ValidateAndEmitRequest(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. 

March 27th, 2015 2:35pm

Hi Felix Blaga,

Thanks for posting in MSDN forum.

This forum is for developers discussing developing issues about apps for Office. Since the issue is more relative to Exchange service, I would like to move it to Exchange Server Development forum.

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.

Thanks for your understanding.

Regards & Fei

Free Windows Admin Tool Kit Click here and download it now
March 30th, 2015 9:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics