我正在尝试从Office 365管理API获取元数据。当我拨打以下网址时
resource = "https://manage.office.com/api/v1.0/tenant-id/ServiceComms/Messages"
我得到响应,并且在内容中,我有以下信息(我已用名称替换了租户GUID):
{
"@odata.context": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata#Messages",
"value": [
{
"@odata.type": "#Microsoft.Office365ServiceComms.ExposedContracts.Message",
"@odata.id": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/Messages('LY177449')",
"@odata.editLink": "https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/Messages('LY177449')",
"AffectedWorkloadDisplayNames@odata.type": "#Collection(String)",
"AffectedWorkloadDisplayNames": [],
"AffectedWorkloadNames@odata.type": "#Collection(String)",
"AffectedWorkloadNames": [
根据回复,我假设我可以从https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata
检索元数据
但是当我对该URL进行身份验证调用时,我只会收到内部服务器错误消息
string resource =
"https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata";
using(HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0);
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", _authResult.AccessToken);
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
HttpResponseMessage response = await httpClient.GetAsync(resource);
}
在httpClient
中,我有2个标题,Authorization: bearer token
(很好用)和Accept: application/json
在HttpResponseMessage response
中,我得到一个500 Internal Server Error
。没有其他信息。
我不明白我在这里做错了。有谁知道如何从Office 365服务通信API获取元数据?
答案 0 :(得分:0)
我建议您检查响应的内容,看看它是否提供任何其他信息。
例如
当服务遇到错误时,它将报告错误响应 使用标准的HTTP错误代码语法将代码提供给调用方。按照 OData V4规范,正文中包含其他信息 失败的调用作为单个JSON对象。以下是 完整的JSON错误正文的示例:
{
"error":{
"code":"AF5000. An internal server error occurred.",
"message": "Retry the request."
}
}
引用Office 365 Service Communications API reference (Preview): Errors
当我测试您的示例网址
https://office365servicecomms-prod.cloudapp.net/api/v1.0/tenant-id/$metadata#CurrentStatus
我得到一个空引用异常
System.NullReferenceException: Object reference not set to an instance of an object.
at Autofac.Integration.WebApi.AutofacWebApiFilterProvider.GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.<ReverseIterator>d__75`1.MoveNext()
at System.Web.Http.Controllers.HttpActionDescriptor.<RemoveDuplicates>d__3.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.<ReverseIterator>d__75`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Web.Http.Controllers.HttpActionDescriptor.InitializeFilterPipeline()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Web.Http.Controllers.HttpActionDescriptor.GetFilterGrouping()
at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Office365ServiceComms.MessageHandlers.RequestResponseLogHandler.<SendAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()
这是可以预期的,因为我没有租户ID或auth令牌。
并且由于此API处于预览状态,因此很可能是他们这方面的实际问题/错误。如果他们有能力,应该考虑提出一个问题。
当我测试odata examples at odata.org时,调用odata.context
将按预期从其示例中返回模式。