有人可以帮助您如何使用“ DiscoveryWebProxyClient ”类对象吗?
我已经在“Azure Active Directory”中注册了一个web / api应用程序。
AuthenticationContext auth = new AuthenticationContext("login.microsoftonline.com[myTenantId]");
ClientCredential clientCred = new ClientCredential("[ClientId]", "[ClinetSecret]");
string token = auth.AcquireToken("[myDynamics365_URL]", clientCred).AccessToken;
using (var orgService = new OrganizationWebProxyClient(GetServiceUrl("[myDynamics365_URL]+/xrmservices/2011/organization.svc/web?SdkClientVersion=9.0"), false))
{
orgService .HeaderToken = token;
var request = new OrganizationRequest(){RequestName = "WhoAmI"};
var response= orgService.Execute(new WhoAmIRequest()) as WhoAmIResponse;
}
使用上面的令牌[通过ADAL],我能够成功获得“ WhoAmI ”请求的响应。
使用DiscoveryWebProxyClient:
DiscoveryWebProxyClient discoveryWebProxyClient = new DiscoveryWebProxyClient(new Uri("disco.crm8.dynamics.com/.../web"))
{
HeaderToken = token,
};
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
var discResponse = discoveryWebProxyClient.Execute(orgRequest);}
当我尝试使用相同的令牌[By ADAL]获取“RetrieveOrganizationsRequest”的响应时,我收到以下异常。
例外: HTTP请求未经授权,客户端身份验证方案为“匿名”。从服务器收到的身份验证标头是'Bearer error = access_denied,error_description =身份验证失败。故障单[-----------],authorization_uri = login.windows.net /.../ authorize,resource_id = disco.crm8.dynamics.com'。
有人可以帮助我使用“DiscoveryWebProxyClient”来帮助我吗?