gpt4 book ai didi

c# - 通过 odata.context Url 获取 Office 365 Service Communications API 的元数据

转载 作者:行者123 更新时间:2023-11-30 12:54:26 24 4
gpt4 key购买 nike

我正在尝试从 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 个 header ,Authorization: bearer token(工作正常)和 Accept: application/json/p>

HttpResponseMessage 响应 中,我得到一个 500 Internal Server Error。没有其他信息。

我不明白我在这里做错了什么。有谁知道如何从 Office 365 服务通信 API 获取元数据?

最佳答案

我建议您检查响应的内容,看看它是否提供了任何其他信息。

例如

When the service encounters an error, it reports the error response code to the caller, using standard HTTP error-code syntax. As per OData V4 specification, additional information is included in the body of the failed call as a single JSON object. The following is an example of a full JSON error body:

{ 
"error":{
"code":"AF5000. An internal server error occurred.",
"message": "Retry the request."
}
}

引用 Office 365 Service Communications API reference (Preview): Errors

当我测试您的示例 URL 时

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 也没有授权 token 。

并且由于此 API 处于预览状态,因此很可能是他们方面的实际问题/错误。如果他们有这种能力,应该考虑提出问题。

当我测试 odata examples at odata.org ,调用 odata.context 按预期从他们的示例中返回架构。

关于c# - 通过 odata.context Url 获取 Office 365 Service Communications API 的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56596635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com