C#:使用 Azure Graph API 2.0 将用户添加到组时,“更改集不能包含对超过‘1’个源资源的更改”
C#: 'A change set cannot include changes to more than '1' source resources' when adding a user To Group using Azure Graph API 2.0
我正在尝试使用 Azure GraphClient API 2.0(2.0.5,最新版本为 2/9/2015)将用户添加到组中,但有以下例外情况:
System.AggregateException:出现一个或多个错误。 ---> System.Data.Services.Client.DataServiceRequestException: 处理此请求时发生错误。 ---> System.Data.Services.Client.DataServiceClientException: {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"更改集不能包含对超过“1”个源资源的更改。"},"values":null}}
使用以下代码片段:
IUser userToAdd = GetUserByObjectId('user_object_id');
Group groupToUpdate = GetGroupByObjectId('group_object_id') as Group;
if (userToAdd != null && groupToUpdate != null)
{
groupToUpdate.Members.Add(userToAdd as DirectoryObject);
groupToUpdate.UpdateAsync().Wait(); <---------- Exception thrown at this point
}
到目前为止我做了什么:
1.经过测试,注释掉'groupToUpdate.Members.Add'不会抛出异常
2. 我查找了错误消息“更改集不能包含对超过‘1’个源资源的更改”,但无法找到任何引用。
3. 检查 https://github.com/AzureADSamples/ConsoleApp-GraphAPI-DotNet 中的添加成员到组示例以确保我没有做错。
4. 我确认所有其他操作,如CRUD 用户、创建组、删除组、搜索和查找功能都可以正常工作。
如有任何帮助,我们将不胜感激。
更新(2/10/2015):
我已经捕获了 Fiddler 跟踪日志。
请求顺序:
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
9 201 HTTPS graph.windows.net /%TENANT_ID%/groups?api-version=1.5 576 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
10 200 HTTPS graph.windows.net /%TENANT_ID%/groups?api-version=1.5 13,242 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
11 200 HTTPS graph.windows.net /%TENANT_ID%/groups/%GROUP_ID%?api-version=1.5 576 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
12 200 HTTPS graph.windows.net /%TENANT_ID%/users/%USER_ID%?api-version=1.5 1,083 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
13 400 HTTPS graph.windows.net /%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group/members?api-version=1.5 164 private application/json;odata=minimalmetadata;charset=utf-8 w3wp:2280
14 204 HTTPS graph.windows.net /%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group?api-version=1.5 0 no-cache; Expires: -1 w3wp:2280
每个请求详细信息:
POST https://graph.windows.net/%TENANT_ID%/groups?api-version=1.5 HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
Content-Length: 191
Expect: 100-continue
{"odata.type":"Microsoft.DirectoryServices.Group","description":"test@%DOMAIN%","displayName":"TESTGROUP","mailEnabled":false,"mailNickname":"nickname","securityEnabled":true}
HTTP/1.1 201 Created
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Location: https://graph.windows.net/%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: 6a690e15-xxxx-xxxx-xxxx-35d52ebd5050
client-request-id: e537b83b-xxxx-xxxx-xxxx-bc80c5025c71
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:31 GMT
Content-Length: 576
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.Group/@Element","odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"%GROUP_ID%","deletionTimestamp":null,"description":"test@%DOMAIN%","dirSyncEnabled":null,"displayName":"TESTGROUP","lastDirSyncTime":null,"mail":null,"mailNickname":"%MAIL_NICKNAME%","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true}
------------------------------------------------------------------
GET https://graph.windows.net/%TENANT_ID%/groups?api-version=1.5 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: d74a33fb-xxxx-xxxx-xxxx-43e3e5c5a35f
client-request-id: 1d53a420-xxxx-xxxx-xxxx-151596872026
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:33 GMT
Content-Length: 13242
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.Group","value":[{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"%GROUP_ID%","deletionTimestamp":null,"description":"test@%DOMAIN%","dirSyncEnabled":null,"displayName":"TESTGROUP","lastDirSyncTime":null,"mail":null,"mailNickname":"%MAIL_NICKNAME%","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"0c27bdbc-xxxx-xxxx-xxxx-66fd5f63d798","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncPasswordSet","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncPasswordSet","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"0cc118be-xxxx-xxxx-xxxx-b624ae770d19","deletionTimestamp":null,"description":"DNS clients who are permitted to perform dynamic updates on behalf of some other clients (such as DHCP servers).","dirSyncEnabled":true,"displayName":"DnsUpdateProxy","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"DnsUpdateProxy","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"14072b09-xxxx-xxxx-xxxx-e537635d34c0","deletionTimestamp":null,"description":"DNS clients who are permitted to perform dynamic updates on behalf of some other clients (such as DHCP servers).","dirSyncEnabled":null,"displayName":"DnsUpdateProxy","lastDirSyncTime":null,"mail":null,"mailNickname":"DnsUpdateProxy","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"19f93a9d-xxxx-xxxx-xxxx-b91ece8b24f9","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncOperators","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncOperators","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"1f75b1c0-xxxx-xxxx-xxxx-e550328f8973","deletionTimestamp":null,"description":"Members of this group can access WMI resources over management protocols (such as WS-Management via the Windows Remote Management service). This applies only to WMI namespaces that grant access to the user.","dirSyncEnabled":null,"displayName":"WinRMRemoteWMIUsers__","lastDirSyncTime":null,"mail":null,"mailNickname":"WinRMRemoteWMIUsers__","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"413668fe-xxxx-xxxx-xxxx-a0ebcf476dfc","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncBrowse","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncBrowse","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-1112","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"4be872db-xxxx-xxxx-xxxx-2eb7079a44ed","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"HelpLibraryUpdaters","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"HelpLibraryUpdaters","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"6cebb7a3-xxxx-xxxx-xxxx-f3cc66597c7f","deletionTimestamp":null,"description":"DNS Administrators Group","dirSyncEnabled":null,"displayName":"DnsAdmins","lastDirSyncTime":null,"mail":null,"mailNickname":"DnsAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"6d5e8c74-xxxx-xxxx-xxxx-e74dad7e6fd9","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Browser.","dirSyncEnabled":null,"displayName":"SQLServer2005SQLBrowserUser$%DOMAIN%","lastDirSyncTime":null,"mail":null,"mailNickname":"SQLServer2005SQLBrowserUser_%DOMAIN%","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"6ff48cbf-xxxx-xxxx-xxxx-2be51fd0f1bb","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncAdmins","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"8f19946b-xxxx-xxxx-xxxx-8fe4448340e8","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Browser.","dirSyncEnabled":true,"displayName":"SQLServer2005SQLBrowserUser$","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServer2005SQLBrowserUser","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"9fa2e738-xxxx-xxxx-xxxx-009211a5a4db","deletionTimestamp":null,"description":"Members of this group can access WMI resources over management protocols (such as WS-Management via the Windows Remote Management service). This applies only to WMI namespaces that grant access to the user.","dirSyncEnabled":true,"displayName":"WinRMRemoteWMIUsers__","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"WinRMRemoteWMIUsers__","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"b30426e5-xxxx-xxxx-xxxx-e7c1074d121e","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncBrowse","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncBrowse","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"b351bd7f-xxxx-xxxx-xxxx-d7cc91852941","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncPasswordSet","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncPasswordSet","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"b8c3e590-xxxx-xxxx-xxxx-82c3ad150d79","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Active Directory Helper in SQL Server 2008.","dirSyncEnabled":true,"displayName":"SQLServerMSSQLServerADHelperUser","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServerMSSQLServerADHelperUser","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"ba74d1e1-xxxx-xxxx-xxxx-ba7733c5f248","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncJoiners","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncJoiners","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"c302433d-fa52-40fc-97bb-d4b17331db77","deletionTimestamp":null,"description":"Administrators for %DOMAIN%","dirSyncEnabled":null,"displayName":"%DOMAIN% Administrators","lastDirSyncTime":null,"mail":null,"mailNickname":"d9026cd3-xxxx-xxxx-xxxx-f1b90bf7935c","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"c657ef3c-xxxx-xxxx-xxxx-b9f48cf659da","deletionTimestamp":null,"description":"DNS Administrators Group","dirSyncEnabled":true,"displayName":"DnsAdmins","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"DnsAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"cc4ec8c6-xxxx-xxxx-xxxx-ab5a1b2ea5f3","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"Administrators","lastDirSyncTime":null,"mail":null,"mailNickname":"BposMailNickName","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"cda3c0e8-xxxx-xxxx-xxxx-964323393fe0","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Agent.","dirSyncEnabled":true,"displayName":"SQLServerSQLAgentUser$SQLEXPRESS","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServerSQLAgentUser_SQLEXPRESS","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"e29d60e1-xxxx-xxxx-xxxx-c4c553ae802c","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncAdmins","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"e69fa9da-a214-4e32-a1f3-8064e3413ffa","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncOperators","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncOperators","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"eca4dcea-xxxx-xxxx-xxxx-5bfdb52cc127","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the login account for the specified instance of SQL Server.","dirSyncEnabled":true,"displayName":"SQLServerMSSQLUser$SQLEXPRESS","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServerMSSQLUser_SQLEXPRESS","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"f509a5a9-xxxx-xxxx-xxxx-eb6e6c4d1883","deletionTimestamp":null,"description":"demo","dirSyncEnabled":null,"displayName":"demo","lastDirSyncTime":null,"mail":null,"mailNickname":"b5ecf2f6-xxxx-xxxx-xxxx-0056132ccac4","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true}]}
------------------------------------------------------------------
GET https://graph.windows.net/%TENANT_ID%/groups/%GROUP_ID%?api-version=1.5 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_2%
request-id: 1ae63825-xxxx-xxxx-xxxx-10135628a629
client-request-id: 6c971ab8-xxxx-xxxx-xxxx-4a794cdf8fb9
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:34 GMT
Content-Length: 576
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.Group/@Element","odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"%GROUP_ID%","deletionTimestamp":null,"description":"test@%DOMAIN%","dirSyncEnabled":null,"displayName":"TESTGROUP","lastDirSyncTime":null,"mail":null,"mailNickname":"%MAIL_NICKNAME%","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true}
------------------------------------------------------------------
GET https://graph.windows.net/%TENANT_ID%/users/%USER_ID%?api-version=1.5 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: 99314ed2-xxxx-xxxx-xxxx-ee71fd4ffbfe
client-request-id: d6b9b8a2-xxxx-xxxx-xxxx-98ec20e65198
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:34 GMT
Content-Length: 1083
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element","odata.type":"Microsoft.DirectoryServices.User","objectType":"User","objectId":"%USER_ID%","deletionTimestamp":null,"accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"John Smith","facsimileTelephoneNumber":null,"givenName":"John","immutableId":null,"jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"%DOMAIN%ONMICROSOFT","mobile":null,"onPremisesSecurityIdentifier":null,"otherMails":["jsmith@%DOMAIN%"],"passwordPolicies":null,"passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":"en-us","provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"sipProxyAddress":null,"state":null,"streetAddress":null,"surname":"Smith","telephoneNumber":null,"usageLocation":"US","userPrincipalName":"jsmith@%DOMAIN%.onmicrosoft.com","userType":"Member"}
------------------------------------------------------------------
POST https://graph.windows.net/%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group/members?api-version=1.5 HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
Content-Length: 49
Expect: 100-continue
{"odata.type":"Microsoft.DirectoryServices.User"}
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: application/json;odata=minimalmetadata;charset=utf-8
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: 856504e9-xxxx-xxxx-xxxx-5bd2e6c64d44
client-request-id: a4ce7205-xxxx-xxxx-xxxx-77fad62c00f7
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:34 GMT
Content-Length: 164
{"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"A change set cannot include changes to more than '1' source resources."},"values":null}}
------------------------------------------------------------------
MERGE https://graph.windows.net/%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group?api-version=1.5 HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
Content-Length: 50
Expect: 100-continue
{"odata.type":"Microsoft.DirectoryServices.Group"}
HTTP/1.1 204 No Content
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_2%
request-id: f05a4c03-xxxx-xxxx-xxxx-fc245fd03452
client-request-id: f3627ada-xxxx-xxxx-xxxx-6c54958c5613
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:35 GMT
------------------------------------------------------------------
更新(2015 年 2 月 15 日)
更多代码:
private async Task<String> AcquireToken()
{
if (String.IsNullOrEmpty(AccessToken))
{
throw new Exception("Authorization is Required.");
}
else
{
return AccessToken;
}
}
private ActiveDirectoryClient GetActiveDirectoryClient()
{
Uri baseServiceUri = new Uri('https://graph.windows.net');
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri(baseServiceUri , 'tenant_id'), async () => { return AccessToken; });
return activeDirectoryClient;
}
private IUser GetUserByObjectId(String objectId)
{
try
{
ActiveDirectoryClient client = GetActiveDirectoryClient();
return client.Users.GetByObjectId(objectId).ExecuteAsync().Result;
}
catch (Exception ex)
{
//handling exceptions
}
}
private IGroup GetGroupByObjectId(String objectId)
{
try
{
ActiveDirectoryClient client = GetActiveDirectoryClient();
return client.Groups.GetByObjectId(objectId).ExecuteAsync().Result;
}
catch (Exception ex)
{
//handling exceptions
}
}
我解决了这个问题,虽然我不知道它为什么解决了它。我所做的是在每次调用 GetUserByObjectId/GetGroupByObjectId 时停止实例化 ActiveDirectoryClient 对象。我缓存它并重用它,然后我不再收到异常。
您使用了多个 ActiveDirectoryClient 实例。使用相同的实例将修复错误。
我正在尝试使用 Azure GraphClient API 2.0(2.0.5,最新版本为 2/9/2015)将用户添加到组中,但有以下例外情况:
System.AggregateException:出现一个或多个错误。 ---> System.Data.Services.Client.DataServiceRequestException: 处理此请求时发生错误。 ---> System.Data.Services.Client.DataServiceClientException: {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"更改集不能包含对超过“1”个源资源的更改。"},"values":null}}
使用以下代码片段:
IUser userToAdd = GetUserByObjectId('user_object_id');
Group groupToUpdate = GetGroupByObjectId('group_object_id') as Group;
if (userToAdd != null && groupToUpdate != null)
{
groupToUpdate.Members.Add(userToAdd as DirectoryObject);
groupToUpdate.UpdateAsync().Wait(); <---------- Exception thrown at this point
}
到目前为止我做了什么: 1.经过测试,注释掉'groupToUpdate.Members.Add'不会抛出异常 2. 我查找了错误消息“更改集不能包含对超过‘1’个源资源的更改”,但无法找到任何引用。 3. 检查 https://github.com/AzureADSamples/ConsoleApp-GraphAPI-DotNet 中的添加成员到组示例以确保我没有做错。 4. 我确认所有其他操作,如CRUD 用户、创建组、删除组、搜索和查找功能都可以正常工作。
如有任何帮助,我们将不胜感激。
更新(2/10/2015):
我已经捕获了 Fiddler 跟踪日志。
请求顺序:
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
9 201 HTTPS graph.windows.net /%TENANT_ID%/groups?api-version=1.5 576 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
10 200 HTTPS graph.windows.net /%TENANT_ID%/groups?api-version=1.5 13,242 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
11 200 HTTPS graph.windows.net /%TENANT_ID%/groups/%GROUP_ID%?api-version=1.5 576 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
12 200 HTTPS graph.windows.net /%TENANT_ID%/users/%USER_ID%?api-version=1.5 1,083 no-cache; Expires: -1 application/json;odata=minimalmetadata;streaming=true;charset=utf-8 w3wp:2280
13 400 HTTPS graph.windows.net /%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group/members?api-version=1.5 164 private application/json;odata=minimalmetadata;charset=utf-8 w3wp:2280
14 204 HTTPS graph.windows.net /%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group?api-version=1.5 0 no-cache; Expires: -1 w3wp:2280
每个请求详细信息:
POST https://graph.windows.net/%TENANT_ID%/groups?api-version=1.5 HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
Content-Length: 191
Expect: 100-continue
{"odata.type":"Microsoft.DirectoryServices.Group","description":"test@%DOMAIN%","displayName":"TESTGROUP","mailEnabled":false,"mailNickname":"nickname","securityEnabled":true}
HTTP/1.1 201 Created
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Location: https://graph.windows.net/%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: 6a690e15-xxxx-xxxx-xxxx-35d52ebd5050
client-request-id: e537b83b-xxxx-xxxx-xxxx-bc80c5025c71
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:31 GMT
Content-Length: 576
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.Group/@Element","odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"%GROUP_ID%","deletionTimestamp":null,"description":"test@%DOMAIN%","dirSyncEnabled":null,"displayName":"TESTGROUP","lastDirSyncTime":null,"mail":null,"mailNickname":"%MAIL_NICKNAME%","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true}
------------------------------------------------------------------
GET https://graph.windows.net/%TENANT_ID%/groups?api-version=1.5 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: d74a33fb-xxxx-xxxx-xxxx-43e3e5c5a35f
client-request-id: 1d53a420-xxxx-xxxx-xxxx-151596872026
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:33 GMT
Content-Length: 13242
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.Group","value":[{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"%GROUP_ID%","deletionTimestamp":null,"description":"test@%DOMAIN%","dirSyncEnabled":null,"displayName":"TESTGROUP","lastDirSyncTime":null,"mail":null,"mailNickname":"%MAIL_NICKNAME%","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"0c27bdbc-xxxx-xxxx-xxxx-66fd5f63d798","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncPasswordSet","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncPasswordSet","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"0cc118be-xxxx-xxxx-xxxx-b624ae770d19","deletionTimestamp":null,"description":"DNS clients who are permitted to perform dynamic updates on behalf of some other clients (such as DHCP servers).","dirSyncEnabled":true,"displayName":"DnsUpdateProxy","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"DnsUpdateProxy","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"14072b09-xxxx-xxxx-xxxx-e537635d34c0","deletionTimestamp":null,"description":"DNS clients who are permitted to perform dynamic updates on behalf of some other clients (such as DHCP servers).","dirSyncEnabled":null,"displayName":"DnsUpdateProxy","lastDirSyncTime":null,"mail":null,"mailNickname":"DnsUpdateProxy","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"19f93a9d-xxxx-xxxx-xxxx-b91ece8b24f9","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncOperators","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncOperators","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"1f75b1c0-xxxx-xxxx-xxxx-e550328f8973","deletionTimestamp":null,"description":"Members of this group can access WMI resources over management protocols (such as WS-Management via the Windows Remote Management service). This applies only to WMI namespaces that grant access to the user.","dirSyncEnabled":null,"displayName":"WinRMRemoteWMIUsers__","lastDirSyncTime":null,"mail":null,"mailNickname":"WinRMRemoteWMIUsers__","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"413668fe-xxxx-xxxx-xxxx-a0ebcf476dfc","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncBrowse","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncBrowse","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-1112","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"4be872db-xxxx-xxxx-xxxx-2eb7079a44ed","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"HelpLibraryUpdaters","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"HelpLibraryUpdaters","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"6cebb7a3-xxxx-xxxx-xxxx-f3cc66597c7f","deletionTimestamp":null,"description":"DNS Administrators Group","dirSyncEnabled":null,"displayName":"DnsAdmins","lastDirSyncTime":null,"mail":null,"mailNickname":"DnsAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"6d5e8c74-xxxx-xxxx-xxxx-e74dad7e6fd9","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Browser.","dirSyncEnabled":null,"displayName":"SQLServer2005SQLBrowserUser$%DOMAIN%","lastDirSyncTime":null,"mail":null,"mailNickname":"SQLServer2005SQLBrowserUser_%DOMAIN%","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"6ff48cbf-xxxx-xxxx-xxxx-2be51fd0f1bb","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncAdmins","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"8f19946b-xxxx-xxxx-xxxx-8fe4448340e8","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Browser.","dirSyncEnabled":true,"displayName":"SQLServer2005SQLBrowserUser$","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServer2005SQLBrowserUser","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"9fa2e738-xxxx-xxxx-xxxx-009211a5a4db","deletionTimestamp":null,"description":"Members of this group can access WMI resources over management protocols (such as WS-Management via the Windows Remote Management service). This applies only to WMI namespaces that grant access to the user.","dirSyncEnabled":true,"displayName":"WinRMRemoteWMIUsers__","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"WinRMRemoteWMIUsers__","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"b30426e5-xxxx-xxxx-xxxx-e7c1074d121e","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncBrowse","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncBrowse","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"b351bd7f-xxxx-xxxx-xxxx-d7cc91852941","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncPasswordSet","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncPasswordSet","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"b8c3e590-xxxx-xxxx-xxxx-82c3ad150d79","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Active Directory Helper in SQL Server 2008.","dirSyncEnabled":true,"displayName":"SQLServerMSSQLServerADHelperUser","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServerMSSQLServerADHelperUser","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"ba74d1e1-xxxx-xxxx-xxxx-ba7733c5f248","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"FIMSyncJoiners","lastDirSyncTime":null,"mail":null,"mailNickname":"FIMSyncJoiners","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1619918607-3034894204-2710842436-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"c302433d-fa52-40fc-97bb-d4b17331db77","deletionTimestamp":null,"description":"Administrators for %DOMAIN%","dirSyncEnabled":null,"displayName":"%DOMAIN% Administrators","lastDirSyncTime":null,"mail":null,"mailNickname":"d9026cd3-xxxx-xxxx-xxxx-f1b90bf7935c","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"c657ef3c-xxxx-xxxx-xxxx-b9f48cf659da","deletionTimestamp":null,"description":"DNS Administrators Group","dirSyncEnabled":true,"displayName":"DnsAdmins","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"DnsAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"cc4ec8c6-xxxx-xxxx-xxxx-ab5a1b2ea5f3","deletionTimestamp":null,"description":null,"dirSyncEnabled":null,"displayName":"Administrators","lastDirSyncTime":null,"mail":null,"mailNickname":"BposMailNickName","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"cda3c0e8-xxxx-xxxx-xxxx-964323393fe0","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the log on account for the associated instance of SQL Server Agent.","dirSyncEnabled":true,"displayName":"SQLServerSQLAgentUser$SQLEXPRESS","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServerSQLAgentUser_SQLEXPRESS","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"e29d60e1-xxxx-xxxx-xxxx-c4c553ae802c","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncAdmins","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncAdmins","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"e69fa9da-a214-4e32-a1f3-8064e3413ffa","deletionTimestamp":null,"description":null,"dirSyncEnabled":true,"displayName":"ADSyncOperators","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"ADSyncOperators","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"eca4dcea-xxxx-xxxx-xxxx-5bfdb52cc127","deletionTimestamp":null,"description":"Members in the group have the required access and privileges to be assigned as the login account for the specified instance of SQL Server.","dirSyncEnabled":true,"displayName":"SQLServerMSSQLUser$SQLEXPRESS","lastDirSyncTime":"2014-12-19T03:38:25Z","mail":null,"mailNickname":"SQLServerMSSQLUser_SQLEXPRESS","mailEnabled":false,"onPremisesSecurityIdentifier":"S-1-5-21-1993123774-3458547345-3703279742-xxxx","provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true},{"odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"f509a5a9-xxxx-xxxx-xxxx-eb6e6c4d1883","deletionTimestamp":null,"description":"demo","dirSyncEnabled":null,"displayName":"demo","lastDirSyncTime":null,"mail":null,"mailNickname":"b5ecf2f6-xxxx-xxxx-xxxx-0056132ccac4","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true}]}
------------------------------------------------------------------
GET https://graph.windows.net/%TENANT_ID%/groups/%GROUP_ID%?api-version=1.5 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_2%
request-id: 1ae63825-xxxx-xxxx-xxxx-10135628a629
client-request-id: 6c971ab8-xxxx-xxxx-xxxx-4a794cdf8fb9
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:34 GMT
Content-Length: 576
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.Group/@Element","odata.type":"Microsoft.DirectoryServices.Group","objectType":"Group","objectId":"%GROUP_ID%","deletionTimestamp":null,"description":"test@%DOMAIN%","dirSyncEnabled":null,"displayName":"TESTGROUP","lastDirSyncTime":null,"mail":null,"mailNickname":"%MAIL_NICKNAME%","mailEnabled":false,"onPremisesSecurityIdentifier":null,"provisioningErrors":[],"proxyAddresses":[],"securityEnabled":true}
------------------------------------------------------------------
GET https://graph.windows.net/%TENANT_ID%/users/%USER_ID%?api-version=1.5 HTTP/1.1
DataServiceVersion: 1.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: 99314ed2-xxxx-xxxx-xxxx-ee71fd4ffbfe
client-request-id: d6b9b8a2-xxxx-xxxx-xxxx-98ec20e65198
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 3.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:34 GMT
Content-Length: 1083
{"odata.metadata":"https://graph.windows.net/%TENANT_ID%/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element","odata.type":"Microsoft.DirectoryServices.User","objectType":"User","objectId":"%USER_ID%","deletionTimestamp":null,"accountEnabled":true,"assignedLicenses":[],"assignedPlans":[],"city":null,"country":null,"department":null,"dirSyncEnabled":null,"displayName":"John Smith","facsimileTelephoneNumber":null,"givenName":"John","immutableId":null,"jobTitle":null,"lastDirSyncTime":null,"mail":null,"mailNickname":"%DOMAIN%ONMICROSOFT","mobile":null,"onPremisesSecurityIdentifier":null,"otherMails":["jsmith@%DOMAIN%"],"passwordPolicies":null,"passwordProfile":null,"physicalDeliveryOfficeName":null,"postalCode":null,"preferredLanguage":"en-us","provisionedPlans":[],"provisioningErrors":[],"proxyAddresses":[],"sipProxyAddress":null,"state":null,"streetAddress":null,"surname":"Smith","telephoneNumber":null,"usageLocation":"US","userPrincipalName":"jsmith@%DOMAIN%.onmicrosoft.com","userType":"Member"}
------------------------------------------------------------------
POST https://graph.windows.net/%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group/members?api-version=1.5 HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
Content-Length: 49
Expect: 100-continue
{"odata.type":"Microsoft.DirectoryServices.User"}
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: application/json;odata=minimalmetadata;charset=utf-8
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_1%
request-id: 856504e9-xxxx-xxxx-xxxx-5bd2e6c64d44
client-request-id: a4ce7205-xxxx-xxxx-xxxx-77fad62c00f7
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:34 GMT
Content-Length: 164
{"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"A change set cannot include changes to more than '1' source resources."},"values":null}}
------------------------------------------------------------------
MERGE https://graph.windows.net/%TENANT_ID%/directoryObjects/%GROUP_ID%/Microsoft.DirectoryServices.Group?api-version=1.5 HTTP/1.1
DataServiceVersion: 3.0;NetFx
MaxDataServiceVersion: 3.0;NetFx
Content-Type: application/json;odata=minimalmetadata
Accept: application/json;odata=minimalmetadata
Accept-Charset: UTF-8
DataServiceUrlConventions: KeyAsSegment
User-Agent: Microsoft ADO.NET Data Services
Authorization: %ACCESS_TOKEN%
X-ClientService-ClientTag: Office 365 API Tools 1.1.0612
Host: graph.windows.net
Content-Length: 50
Expect: 100-continue
{"odata.type":"Microsoft.DirectoryServices.Group"}
HTTP/1.1 204 No Content
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Server: Microsoft-IIS/8.5
ocp-aad-diagnostics-server-name: %SOME_KEY_2%
request-id: f05a4c03-xxxx-xxxx-xxxx-fc245fd03452
client-request-id: f3627ada-xxxx-xxxx-xxxx-6c54958c5613
x-ms-gateway-rewrite: false
x-ms-dirapi-data-contract-version: 1.5
ocp-aad-session-key: %KEY%
X-Content-Type-Options: nosniff
DataServiceVersion: 1.0;
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
Date: Tue, 10 Feb 2015 22:19:35 GMT
------------------------------------------------------------------
更新(2015 年 2 月 15 日) 更多代码:
private async Task<String> AcquireToken()
{
if (String.IsNullOrEmpty(AccessToken))
{
throw new Exception("Authorization is Required.");
}
else
{
return AccessToken;
}
}
private ActiveDirectoryClient GetActiveDirectoryClient()
{
Uri baseServiceUri = new Uri('https://graph.windows.net');
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri(baseServiceUri , 'tenant_id'), async () => { return AccessToken; });
return activeDirectoryClient;
}
private IUser GetUserByObjectId(String objectId)
{
try
{
ActiveDirectoryClient client = GetActiveDirectoryClient();
return client.Users.GetByObjectId(objectId).ExecuteAsync().Result;
}
catch (Exception ex)
{
//handling exceptions
}
}
private IGroup GetGroupByObjectId(String objectId)
{
try
{
ActiveDirectoryClient client = GetActiveDirectoryClient();
return client.Groups.GetByObjectId(objectId).ExecuteAsync().Result;
}
catch (Exception ex)
{
//handling exceptions
}
}
我解决了这个问题,虽然我不知道它为什么解决了它。我所做的是在每次调用 GetUserByObjectId/GetGroupByObjectId 时停止实例化 ActiveDirectoryClient 对象。我缓存它并重用它,然后我不再收到异常。
您使用了多个 ActiveDirectoryClient 实例。使用相同的实例将修复错误。