這裏是下面的代碼段失敗的異常有關的響應與狀態代碼獲取消息404:錯誤404嘗試使用OutlookServicesClient CLAS
var client = new Microsoft.Office365.OutlookServices
.OutlookServicesClient(GetAPIEndpointUri(),
GetOrPrepareApplicationAccessTokenAsync
);
var messageFetcher = client.Users[mailbox].Messages.GetById(itemId);
var message = await messageFetcher.ExecuteAsync();
message.Subject = subject;
await message.UpdateAsync();
其實下面的行失敗:
var message = await messageFetcher.ExecuteAsync();
查看異常詳細信息中的查詢URI,它看起來像這樣:
https://outlook.office365.com/api/Users('mailbox%40domain.onmicrosoft.com')/ Messages('long message
{"message":"An error has occurred.","exceptionMessage":"An error occurred while processing this request.","exceptionType":"Microsoft.OData.Client.DataServiceQueryException","stackTrace":" at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)\r\n at Microsoft.OData.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)\r\n at Microsoft.OData.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)\r\n at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<>c__DisplayClass12`2.<ExecuteSingleAsync>b__10(IAsyncResult i)\r\n at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<ExecuteSingleAsync>d__14`2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Office365.OutlookServices.MessageFetcher.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at [[my code]]\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at [[My code]]","innerException":{"message":"An error has occurred.","exceptionMessage":"NotFound","exceptionType":"Microsoft.OData.Client.DataServiceClientException","stackTrace":" at Microsoft.OData.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)\r\n at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)"}}
異常詳細信息從VS異常asisstant複製:
Microsoft.OData.Client.DataServiceQueryException was caught
HResult=-2146233079
Message=An error occurred while processing this request.
Source=Microsoft.OData.Client
StackTrace:
at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
at Microsoft.OData.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult)
at Microsoft.OData.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)
at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<>c__DisplayClass12`2.<ExecuteSingleAsync>b__10(IAsyncResult i)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Office365.OutlookServices.Extensions.DataServiceContextWrapper.<ExecuteSingleAsync>d__14`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.Office365.OutlookServices.MessageFetcher.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at [[My code]]
InnerException: Microsoft.OData.Client.DataServiceClientException
HResult=-2146233079
Message=NotFound
Source=Microsoft.OData.Client
StatusCode=404
StackTrace:
at Microsoft.OData.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult)
at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult)
InnerException:
ID')
如何獲得訪問令牌:因爲它轉化爲客戶端
var authContext = new AuthenticationContext(
GetAuthorityUrl()
.ToString()
);
var result = await authContext.AcquireTokenAsync(
GetResourceUrl(),
new ClientAssertionCertificate(GetClientId(), AppCertificateHelper.GetCertificate())
);
錯誤信息
響應標題:
[0]: {[request-id, e459455e-8bba-42b9-89cb-f6eb94f67b64]}
[1]: {[X-CalculatedBETarget, HK2PR02MB0868.apcprd02.prod.outlook.com]}
[2]: {[X-BackEndHttpStatus, 404]}
[3]: {[X-DiagInfo, HK2PR02MB0868]}
[4]: {[X-BEServer, HK2PR02MB0868]}
[5]: {[X-FEServer, AM3PR07CA0025]}
[6]: {[Content-Length, 0]}
[7]: {[Date, Fri, 06 Feb 2015 18:43:12 GMT]}
[8]: {[Set-Cookie, ClientId=5MTQKAN4QEAXMVUEF5DF0W; expires=Sat, 06-Feb-2016 18:43:06 GMT; path=/; secure; HttpOnly]}
[9]: {[Server, Microsoft-IIS/8.0]}
[10]: {[X-Powered-By, ASP.NET]}
這是相同的問題http://stackoverflow.com/questions/28333362/getting-cannot-resolve-the-odata-request-url-for-specific-users-on-rest-item? – 2015-02-06 15:33:02
不確定。因爲當我使用Web API HttpClient類發出普通請求時,我得到了這個錯誤400,但是這次使用Office 365工具(用於Outlook的Office365 c#客戶端庫)。爲什麼它給出不同的狀態代碼,如果它是同樣的問題?但是,是的,這是一個失敗的嘗試解決這個問題。 – 2015-02-06 15:42:54
我不確定這是不是相同的錯誤,這就是爲什麼我問:)。你能發佈完整的錯誤響應嗎? – 2015-02-06 15:48:01