Jim*_*eil 5 c# azure-ad-graph-api asp.net-core microsoft-graph-sdks microsoft-graph-api
我们在 .NET Core 2.1上运行,在运行以下查询时有时会出现异常“此平台不支持安全二进制序列化”:
await _adClient.Users[userId].AppRoleAssignments.ExecuteAsync();
Run Code Online (Sandbox Code Playgroud)
重新执行查询通常有效,因此满足某些条件,即在后续请求中未尝试(或成功?)二进制序列化?也就是说,如果我重新启动服务,它通常也会对第一个请求起作用。
我们正在使用旧的 AD Graph 客户端,因为 1) Microsoft Graph 客户端尚不完全支持AppRoleAssignments,2) 支持的内容是测试版的一部分,不建议用于生产用途。
完整的调用堆栈如下:
System.Data.Services.Client.BaseAsyncResult.EndExecute<T>(object source, string method, IAsyncResult asyncResult)
System.Data.Services.Client.QueryResult.EndExecuteQuery<TElement>(object source, string method, IAsyncResult asyncResult)
System.Data.Services.Client.DataServiceRequest.EndExecute<TElement>(object source, DataServiceContext context, string method, IAsyncResult asyncResult)
System.Data.Services.Client.DataServiceQuery<TElement>.EndExecute(IAsyncResult asyncResult)
Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper+<>c__DisplayClass4c<TSource, TInterface>.<ExecuteAsync>b__4a(IAsyncResult r)
System.Threading.Tasks.TaskFactory<TResult>.FromAsyncCoreLogic(IAsyncResult iar, Func<IAsyncResult, TResult> endFunction, Action<IAsyncResult> endAction, Task<TResult> promise, bool requiresSynchronization)
Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper.ExecuteAsync<TSource, TInterface>(DataServiceQuery<TSource> inner)
Microsoft.Azure.ActiveDirectory.GraphClient.AppRoleAssignmentCollection.<ExecuteAsync>b__2()
Merck.SeaMonkey.Api.AzureADApi.Controllers.UserController.GetApplicationRoleAssignments(string userId) in UserController.cs
Run Code Online (Sandbox Code Playgroud)
新的 Microsoft Graph 客户端不是这里的一个选项,尽管我想我们可以下拉到基本 REST 接口,这对我们依赖于图客户端的所有重试逻辑、结果解析等有点工作去做。
更新:给出异常的来源,我们假设在序列化 OData 响应中的实体时存在问题。但是,使用 AD Graph Explorer,我们会看到一个非常简单的响应,即空值数组以及指向实体元数据文档的链接。我们通过删除和添加新的应用程序角色分配使问题经常再次发生,但我们不能强制它 100% 可靠地发生。看起来某些状态正在损坏,也许在某些内部缓存中?
我经常使用该 api 调用 - 但我对旧图使用直接的 Rest httpClient 调用。
我只是将其发布作为参考 - 请注意 url (1.6) 上的明确版本。我还发布了我反序列化的对象,这可能与官方对象模式不匹配。
// OLD Graph End point // like ... https://graph.windows.net/{tenant-id}/users/{id}/appRoleAssignments?api-version=1.6
urlUserInviteToUse = "https://graph.windows.net/" + m_CfgHlp.TenIdInB2C + "/" + ObjFamilyName + "/" + DirObjIdToGet + "/" + ObjFunctionCall + "?api-version=1.6";
Run Code Online (Sandbox Code Playgroud)
由于其余 api 字符串有效负载,我有效地使用JsonConvert.DeserializeObject从有效负载转到对象类。请注意,日期没有被反序列化为日期。
public class AppRoleAssignmentsRoot
{
public string odatametadata { get; set; }
public AppRoleAssignment[] value { get; set; }
}
public class AppRoleAssignment
{
public string odatatype { get; set; }
public string objectType { get; set; }
public string objectId { get; set; }
public object deletionTimestamp { get; set; }
public object creationTimestamp { get; set; }
public string id { get; set; }
public string principalDisplayName { get; set; }
public string principalId { get; set; }
public string principalType { get; set; }
public string resourceDisplayName { get; set; }
public string resourceId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1507 次 |
| 最近记录: |