读取LiveDeviceID.xml以获取密码

时间:2012-09-20 16:26:32

标签: c# xml dynamics-crm

我正在尝试连接到CRM动态在线,如果我从控制台获取以下命令以获取用户名和密码,我就可以到达那里。

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结构,获取两个感兴趣的字符串。 从加密版本变为普通版,这就是问题所在。

1 个答案:

答案 0 :(得分:0)

CRM SDK包含文件sdk \ samplecode \ cs \ helpercode \ deviceidmanager.cs。如果要在线连接Dynamics CRM,此文件应该会有所帮助。

    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());
    }