使用EWS.dll从Office365获取数据时出错

时间:2016-02-12 13:06:10

标签: c# office365 exchangewebservices

我正在尝试使用Microsoft.Exchange.WebServices.dll获取Office365用户帐户电子邮件。但是在加载数据请求时我遇到间歇性错误。电子邮件的加载请求似乎被卡住了,否则会引发异常。

以下是我的示例代码:

_ExchnageService.KeepAlive = true;

PropertySet objProperty = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent);

_Item.Load(objProperty ); // Some times load request didn't respond for hours which appears to be stuck. 

//And some times it thorws following exeption
  

Microsoft.Exchange.WebServices.Data.ServiceRequestException:The   请求失败。无法从传输连接中读取数据:   远程主机强行关闭现有连接。 --->   System.IO.IOException:无法从传输中读取数据   连接:远程强制关闭现有连接   主办。 ---> System.Net.Sockets.SocketException:现有连接   被远程主机强行关闭了   System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32   size,SocketFlags socketFlags)at   System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,   Int32 size)---内部异常堆栈跟踪结束--- at   System.Net.ConnectStream.Read(Byte []缓冲区,Int32偏移量,Int32大小)   在System.IO.Compression.DeflateStream.Read(Byte []数组,Int32   offset,Int32 count)at   System.IO.Compression.GZipStream.Read(Byte []数组,Int32偏移量,   Int32计数)在   Microsoft.Exchange.WebServices.Data.EwsUtilities.CopyStream(流   来源,流目标)   Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(IEwsHttpWebResponse   响应)---内部异常堆栈跟踪结束--- at   Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(IEwsHttpWebResponse   回应)   Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()   在   Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest 1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalLoadPropertiesForItems(IEnumerable 1   items,PropertySet属性集,ServiceErrorHandling errorHandling)
  在Microsoft.Exchange.WebServices.Data.Item.InternalLoad(PropertySet   propertySet)at   Microsoft.Exchange.WebServices.Data.ServiceObject.Load(属性集   propertySet)at   CDT.Office365Reader.DownloadO365Mails.RetriveO365MailValues(项目   p_obj_Item,FolderID folderId,String p_FolderPath,ExchangeService   p_ExchnageService,String p_username)

非常感谢您对此问题的任何帮助或建议。

0 个答案:

没有答案