2014-03-06 286 views
1

我的客户正在使用Dynamics CRM 2011的托管版本,而不是在线版本。使用我的C#代码,我将如何获取用户名,密码,URL和设备ID认证?使用CRM 2011在线,我可以使用此代码进行连接。我相信设备ID是硬编码的。连接到MS Dynamics CRM 2011 Desktop CrmConnection

CrmConnection crmConnection = CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password= 
{2};DeviceID=enterprise-ba9f6b7b2e6d; DevicePassword=passcode;", url, username, password)); 

OrganizationService service = new OrganizationService(crmConnection); 
var xrm = new XrmServiceContext(service); 
return xrm; 

回答

0

试试只删除deviceid和devicepassword。还请检查描述如何使用CrmConnection类的this article

1

托管版本(OnPremise)依赖Active Directory认证(DOMAIN\USERNAME),所以你需要添加Domain到您的连接字符串和(使用LiveID的认证,他们是必要只为CRM在线)删除DeviceIDDevicePassword

的代码将是:

CrmConnection crmConnection = 
CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain)); 
0
ClientCredentials Credentials = new ClientCredentials(); 
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; 

/此URL需要匹配对环境的服务器名和组织。

Uri OrganizationUri = new Uri("http://crm/XRMServices/2011/Organization.svc"); 
Uri HomeRealmUri = null; 

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)) 
{ 

    IOrganizationService service = (IOrganizationService)serviceProxy; 
    if (Context.User.Identity.IsAuthenticated) 
     { 
     string EUserName = Context.User.Identity.Name; 
      string WinUserName = WindowsIdentity.GetCurrent().Name; 
      UserName.InnerText = EUserName; 
     } 
} 


Also add references 
**microsoft.crm.sdk.proxy** 
**microsoft.xrm.sdk**