我正在尝试使用SOAPUI调用MSCRM 365 Web服务,这是我到目前为止所做的
每当我向MSCRM发送请求时,我都会收到“HTTP ERROR 401 - 未经授权:访问被拒绝”
有人有什么想法吗?
谢谢, Nitesh
答案 0 :(得分:0)
由于这是Dynamics 365,因此不会使用用户名/密码进行身份验证。相反,您需要使用OAuth,如链接
中所示https://msdn.microsoft.com/en-us/library/gg327838.aspx
// TODO Substitute your correct CRM root service address,
string resource = "https://mydomain.crm.dynamics.com";
// TODO Substitute your app registration values that can be obtained after you
// register the app in Active Directory on the Microsoft Azure portal.
string clientId = "e5cf0024-a66a-4f16-85ce-99ba97a24bb2";
string redirectUrl = "http://localhost/SdkSample";
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext =
new AuthenticationContext("https://login.windows.net/common", false);
AuthenticationResult result = authContext.AcquireToken(resource, clientId, new
Uri(redirectUrl));
在邮件请求中使用访问令牌:
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0); // 2 minutes
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
另一个选择是从Xrm.Client转移到Xrm.Tools.Connection。请参阅此站点中的示例。