Use XRM tooling with classes generated using the code-generation tool
Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online
The Microsoft.Xrm.Tooling.Connector assembly doesn’t directly provide interfaces for the entity and data context classes generated using the code-generation tool. However, you can use the Microsoft Dynamics 365 connection created by the CrmServiceClient class to set up your entity and data context classes by using the code-generation tool. More information: Create early bound entity classes with the code generation tool (CrmSvcUtil.exe)
To use the Dynamics 365 connection created by the CrmServiceClient class, create a connection to Dynamics 365 by using an instance of this class, and then set the value of the OrganizationServiceProxy object to the CrmServiceClient.OrganizationServiceProxy property.
CrmServiceClient crmSvc = new CrmServiceClient(new System.Net.NetworkCredential("<UserName>", "<Password>",“<Domain>”),"<Server>", "<Port>", "<OrgName>");
// Verify that you are connected.
if (crmSvc != null && crmSvc.IsReady)
{
//Display the CRM version number and org name that you are connected to
Console.WriteLine("Connected to CRM! (Version: {0}; Org: {1}",
crmSvc.ConnectedOrgVersion, crmSvc.ConnectedOrgUniqueName);
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy prox = crmSvc.OrganizationServiceProxy;
}
else
{
// Display the last error.
Console.WriteLine("Error occurred: {0}", crmSvc.LastCrmError);
// Display the last exception message if any.
Console.WriteLine(crmSvc.LastCrmException.Message);
Console.WriteLine(crmSvc.LastCrmException.Source);
Console.WriteLine(crmSvc.LastCrmException.StackTrace);
return;
}
Note
The OrganizationServiceProxy class isn’t thread safe. While working with the entity and data context classes generated by using the code-generation tool or using .NET Language-Integrated Query (LINQ) to retrieve data, you might consider creating a locking scheme in your code if it runs in a multithreaded environment.
See Also
Use the Organization Service to read and write data or metadata
Build Windows client applications using the XRM tools
Microsoft Dynamics 365
© 2016 Microsoft. All rights reserved. Copyright