I use the following method to connect to the CRM OrganizationService, because I had problems with CrmConnection and Tooling.CrmConnector. This method has been tested for on premise installation with internet facing deployment.
Replace {OrganizationName}
and {Servername}
with the name of the CRM Organisation and URL of the CRM Server. For example: OrganizationName = "xyz", Servername = "crm.dynamics.com"
.
using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;
string serviceUri = "https://{OrganizationName}.{Servername}/XRMServices/2011/Organization.svc";
var credentials = new ClientCredentials();
credentials.UserName.UserName = "YourUsername";
credentials.UserName.Password = "YourPassword";
var crmOrganizationService = new OrganizationServiceProxy(new Uri(serviceUri), null, credentials, null);
To install the Microsoft.Xrm.Sdk package in a VS project, do the following:
- right-click on Solution Node in Soltion exploerer, choose "Manage NuGet packages for Solution"
- in NuGet Explorer, choose "Browse" and search for "CRM SDK 2016"
- Choose
Microsoft.CrmSdk.CoreAssemblies
, select the project into which you want to install the package, and click "Install"