1

我正在尝试连接到 CRM Dynamics On-line,如果我从控制台运行以下命令以获取用户名和密码,我可以到达那里。

deviceregistration.exe /operation:show

显然,如果我能以编程方式读取包含信息的 XML,那就更好了。然而,文件的内容被可怕地加密,看起来像这样。

<Data version="1">
  <User username="1kz9u5e4t4br4nah8sm61coc" type="Logical">
    <Pwd>
      AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAASLr2v6+hUU2goUw2ivLu9AAAAAACAAAAAAA 
      QZgAAAAEAACAAAABvPcbpZtXzDjyRoQAm19c71KA3J6TpyU0rieu4WY/1OgAAAAAOgA
      AAAAIAACAAAAAT5Aunf6PBWDRp7UPKYrcP33tniAfAHf1MzEjcUAvVKSAAAAArJkRAv
      Ml+cgNy8fUscH//u41scGezSw+OOvOkpn86r0AAAADLmCwYMLVw+Qo5hPwxnlawMW7s
      0fvMJJkM1UiyfBQ49nJOF7v0pa32DtFFluDsjGv4Yddj7j+FtNiYNxmvzc0l
    </Pwd>
  </User>
</Data>

如何使用 C# 获取真实数据?请注意,我知道如何访问该文件、读取其内容并处理获取两个感兴趣的字符串的 XML 结构。它从加密版本变成了普通版本,这就是问题所在。

4

1 回答 1

0

CRM SDK 包含文件 sdk\samplecode\cs\helpercode\deviceidmanager.cs。如果您想连接 Dynamics CRM On-Line,此文件应该会有所帮助。

    ClientCredentials credentials = new ClientCredentials();
    credentials.UserName.UserName = userName;
    credentials.UserName.UserName = userName;
    credentials.UserName.Password = password;

    IServiceManagement<IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(organizationUrl));

    AuthenticationCredentials authCredentials = new AuthenticationCredentials();
    authCredentials.ClientCredentials = credentials;
    authCredentials.SupportingCredentials = new AuthenticationCredentials();
    authCredentials.SupportingCredentials.ClientCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice();
    AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);
    var organizationTokenResponse = tokenCredentials.SecurityTokenResponse;

    OrganizationServiceProxy _serviceProxy;
    IOrganizationService _service;
    using (_serviceProxy = new OrganizationServiceProxy(orgServiceManagement, organizationTokenResponse))
    {
        _service = (IOrganizationService)_serviceProxy;

        WhoAmIResponse response = (WhoAmIResponse)_service.Execute(new WhoAmIRequest());
        Console.WriteLine(response.UserId.ToString());
    }
于 2012-09-21T09:06:51.663 回答