Dynamics crm MS crm帐户创建:System.Net.WebException:请求失败,HTTP状态401:未经授权

Dynamics crm MS crm帐户创建:System.Net.WebException:请求失败,HTTP状态401:未经授权,dynamics-crm,dynamics-crm-4,Dynamics Crm,Dynamics Crm 4,我正在使用 我已登录到远程服务器以访问Visual studio和MS CRM。我从SDK中获取了示例代码,并尝试运行代码: CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = "AdventureWorksCycle"; CrmService service = new CrmService(); servic

我正在使用 我已登录到远程服务器以访问Visual studio和MS CRM。我从SDK中获取了示例代码,并尝试运行代码:

CrmAuthenticationToken token = new CrmAuthenticationToken();

token.AuthenticationType = 0;

token.OrganizationName = "AdventureWorksCycle";

CrmService service = new CrmService();
service.Url= "http://10.16.16.205:5555/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;

service.Credentials = new System.Net.NetworkCredential"username", "password", "domain");

// Create the account object.
account account = new account();

// Set the properties of the account object.
account.name = "Fourth Coffee123";
account.address1_line1 = "29 Market St.";
account.address1_city = "Sam";
account.address1_stateorprovince = "MT1";
account.address1_postalcode = "9999";
account.donotbulkemail = new CrmBoolean();
account.donotbulkemail.Value = true;

// Create the target object for the request.
TargetCreateAccount target = new TargetCreateAccount();

// Set the properties of the target object.
target.Account = account;

// Create the request object.
CreateRequest create = new CreateRequest();

// Set the properties of the request object.
create.Target = target;

// Execute the request.
CreateResponse created = (CreateResponse)service.Execute(create);
我正在为此使用Crm Web服务,但引发异常:

例外情况详情:

System.Net.WebException:请求 HTTP状态为401时失败: 未经授权

源错误:

第114行:[返回:System.Xml.Serialization.xmlementAttribute(“响应”)]

第115行:公共响应执行(请求){

第116行:**object[]results=this.Invoke(“执行”),新对象[]*{**

第117行:请求});


第118行:返回((响应)(结果[0]);

您缺少的一件事是真实的用户名和密码。我假设您在回答此问题时忽略了这一点

是否已检查用于web服务调用的用户的安全角色?如果尚未检查,请将此用户添加到系统管理员角色

在CRM中,经常出现这种错误,它与安全性无关,而与其他因素有关

首先打开CRM跟踪并查看。这将为您提供更多错误详细信息。以下是如何:

您还可以尝试使用我的异常格式化程序获取有关错误的更多详细信息。这是一个扩展类,允许您格式化异常并将其打印到标准输出或http响应。请在此处查找:

这样使用它:

try {
   // do all your stuff
} catch (Exception ex) {
   ex.Print();
}
请注意,在格式化的异常输出中,您可以看到反序列化的“Details”属性,这样您就可以看到文本版本。这是CRM大部分时间隐藏真正异常的地方