-->

Outlook AddIn Mobile Issue - not working in mobile

2019-08-19 21:40发布

问题:

I have the bellow error in Microsoft exchange server service, but only on mobiles as same code works for Desktops and web.

ERROR MESSAGE:

System.Net.WebException: The remote server returned an error: (401) Unauthorized.

at System.Net.HttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() in \REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\EwsHttpWebRequest.cs:line 113 at

Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs: line 821The request failed.

The remote server returned an error: (401) Unauthorized.

CODE SNIPPET:

// Create an ExchangeService object, set the credentials and the EWS URL.
ExchangeService exchangeService = new ExchangeService();
exchangeService.Credentials = new OAuthCredentials(attachmentToken);
exchangeService.Url = new Uri(ewsUrl);
exchangeService.UseDefaultCredentials = true;
exchangeService.PreAuthenticate = true;
try
{
var getAttachmentsResponse =exchangeService.GetAttachments(attachmentIds.ToArray(),null,new PropertySet(BasePropertySet.FirstClassProperties,ItemSchema.MimeContent));
}
catch (Exception ex)
{
var errMsg = ex.Message;
var errInnerException = ex.InnerException;
message += "Inner Exception :" + errInnerException;
}