Use XRM tooling to connect to CRM

 

Applies To: Dynamics CRM 2015

To connect to Microsoft Dynamics CRM, you create an instance of the CrmServiceClient class, and then use one of the constructors to connect. Each method call by an object of this class is considered an atomic unit of work, and all the calls to Microsoft Dynamics CRM are thread safe.

In this topic

Connect to CRM using OrganizationServiceProxy

Connect to CRM Online (Live ID)

Connect to CRM Online (Office 365)

Connect to CRM on-premises (Active Directory)

Connect to CRM Internet-facing deployment (IFD)

Connect to CRM (Claims-based)

Optional parameters for all the constructors

Determine your connection status

Connect to CRM using OrganizationServiceProxy

Use the following constructor to connect to CRM using the user-provided OrganizationServiceProxy instance.

CrmServiceClient crmSvc = new CrmServiceClient(<orgServiceproxy>);

Connect to CRM Online (Live ID)

Use the following constructor.

CrmServiceClient crmSvc = new CrmServiceClient("<LiveID>", "<Password>", "<CRMonlineRegion>", "<OrgName>");

Valid values for the <CRMonlineRegion> parameter are: NorthAmerica, EMEA, APAC, SouthAmerica, Oceania, Japan, and NorthAmerica2. If you set this to String.Empty, it will search servers in all the regions for the CRM organization. For the <OrgName> parameter, you can specify either the unique or friendly name.

Connect to CRM Online (Office 365)

Use the following constructor.

CrmServiceClient crmSvc = new CrmServiceClient("<UserName>", "<Password>", "<CRMonlineRegion>", "<OrgName>", isOffice365:true);

Valid values for the <CRMonlineRegion> parameter are: NorthAmerica, EMEA, APAC, SouthAmerica, Oceania, Japan, and NorthAmerica2. If you set this to String.Empty, it will search servers in all the regions for the CRM organization. For the <OrgName> parameter, you can specify either the unique or friendly name.

Connect to CRM on-premises (Active Directory)

Use the following constructor.

CrmServiceClient crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("<UserName>", "<Password>", “<Domain>”),"<Server>", "<Port>", "<OrgName>");

This will run an Active Directory authentication based on the specified domain. For the <Server> parameter, specify the host name of your CRM server; for example: crmtest. For the <OrgName> parameter, you can specify either the unique or friendly name.

Connect to CRM Internet-facing deployment (IFD)

Use the following constructor.

CrmServiceClient crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("<UserName>", "<Password>", “<Domain>”), AuthenticationType.IFD, "<Server>", "<Port>", "<OrgName>");

This method will run a claims-based authentication based on the specified local domain. This is useful for customers that use AD FS, and have configured their CRM server as claims, where the user population lives in the same AD FS domain as the CRM server. For the <Server> parameter, specify the host name of your CRM server; for example: crmtest. For the <OrgName> parameter, you can specify either the unique or friendly name.

Connect to CRM (Claims-based)

Use the following constructor.

CrmServiceClient crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("<UserName>", "<Password>", “<Domain>”, "<HomeRealm>"),"<Server>", "<Port>", "<OrgName>");

This method will run a claims-based authentication against the specified Home realm. This is useful for customers that use AD FS, and have configured their CRM server as claims, where the user population lives in the same AD FS domain as the CRM server. For the <Server> parameter, specify the host name of your CRM server; for example: crmtest. For the <OrgName> parameter, you can specify either the unique or friendly name.

Optional parameters for all the constructors

These are the optional parameters that you can use with each of the constructors shown previously.

  • useUniqueInstance: Indicates whether to reuse an existing connection if recalled while the connection is still active. Default is false. If set to true, this will force the system to create a unique connection.

  • useSSL: Indicates whether to use SSL to connect to CRM. Defaults to false, that is, use http://. If set to true, it will use https://.

  • orgDetail: Defaults to null. If set, this is returned from a query to the Discovery service, and is generally used as the second leg of an organization selection process.

Determine your connection status

To determine if the connection request was successful, check the value of the CrmServiceClient.IsReady property. If true, the connection is successful, and you are ready to work. Otherwise, check the values of the CrmServiceClient. LastCrmError and CrmServiceClient.LastCrmException properties for the cause of the connection failure.

See Also

Use PowerShell cmdlets for XRM tooling to connect to CRM
Use XRM tooling to execute actions in CRM
Sample: Quick start for Microsoft Dynamics CRM
Build Windows client applications using the XRM tools

© 2016 Microsoft. All rights reserved. Copyright