【问题标题】:MS crm Account Creation: System.Net.WebException: The request failed with HTTP status 401: UnauthorizedMS crm 帐户创建:System.Net.WebException:请求失败,HTTP 状态 401:未经授权
【发布时间】:2010-11-19 13:53:39
【问题描述】:

我正在使用 我登录到远程服务器以访问 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 失败: 未经授权。

来源错误:

Line 114: [return: System.Xml.Serialization.XmlElementAttribute("Response")]

Line 115: public Response Execute(Request Request) {

Line 116: ***object[] results = this.Invoke("Execute", new object[]* {**

Line 117: Request});

Line 118: return ((Response)(results[0]));

【问题讨论】:

    标签: dynamics-crm dynamics-crm-4


    【解决方案1】:

    您缺少的一件事是真实的用户名和密码。我假设您出于此问题的目的省略了这一点。

    您是否检查了用于 Web 服务调用的用户的安全角色?如果您尚未将此用户添加到系统管理员角色中。

    对于 CRM,此错误通常与安全性无关,而是完全不同。

    首先打开 CRM 跟踪并查看那里。这将为您提供更多错误详细信息。就是这样: http://support.microsoft.com/kb/907490

    您也可以尝试使用我的异常格式化程序来获取有关错误的更多详细信息。这是一个扩展类,允许您格式化异常并将其打印到标准输出或 http 响应。在这里找到它: http://paste.ly/5Y66

    这样使用:

    try {
       // do all your stuff
    } catch (Exception ex) {
       ex.Print();
    }
    

    请注意,在格式化的异常输出中,您可以看到反序列化的“详细信息”属性,以便您可以看到文本版本。这是 CRM 大部分时间隐藏真正异常的地方。

    【讨论】:

      猜你喜欢
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2012-06-30
      • 2012-11-27
      • 1970-01-01
      • 2011-03-18
      相关资源
      最近更新 更多