2
votes

I have a problem when try to connect to MS CRM v9

I used this code to connect:

Uri organizationUri = new Uri(OrgUrl);
AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = UserName;
authCredentials.ClientCredentials.UserName.Password = Password;
OrganizationServiceProxy organizationProxy = new OrganizationServiceProxy(organizationUri, null, authCredentials.ClientCredentials, null);
organizationProxy.EnableProxyTypes();`
var _service = organizationProxy;

This is the Exception message

HResult=-2146233079 Message=Metadata contains a reference that cannot be resolved: 'https://myOrg.api.crm4.dynamics.com/XRMServices/2011/Organization.svc?wsdl&sdkversion=9'. InnerException: HResult=-2146233079 Message=The underlying connection was closed: An unexpected error occurred on a send. InnerException: HResult=-2146232800 Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. InnerException: ErrorCode=10054 HResult=-2147467259 Message=An existing connection was forcibly closed by the remote host

Did anyone face this problem before. PS: this code is running before in the same project

2

2 Answers

3
votes

It looks like you need to update your SDK references to the new 9.0 SDK references. There isn't a single download any more for the SDK, instead you have to use NuGet (https://blogs.msdn.microsoft.com/crm/2017/11/01/whats-new-for-customer-engagement-developer-documentation-in-version-9-0/)

No more monolithic SDK download Probably the greatest single change is that we are no longer providing a single download package for all the documentation, tools and sample code. Going forward, instead of shipping a single package with everything in it, we will offer an a-la-carte approach so that you can download the individual things as you need them.

Get the assemblies and tools you need. SDK assemblies and tools will be distributed only via NuGet. We will provide a script that will allow you to download the assemblies and tools from NuGet. See Where to find the NuGet SDK packages and Download tools from NuGet.

Self-serve offline content generation. The new docs.microsoft.com site will allow you to download a PDF for any of our content areas so that you can read and search the documentation while offline.

Sample code availability. All our sample code will be available on msdn.microsoft.com or on GitHub. The code.msdn.microsoft.com site is designed for sample code and provides a good experience as well as providing us better metrics on usage.

Download only the pieces you need. Various assets we have included in the download package will be available as individual downloads. This way, if one of the assets needs to be updated we can just update it without releasing the entire SDK package.

https://www.nuget.org/profiles/crmsdk has a list of all the SDK DLLs you might need. Specifically https://www.nuget.org/packages/Microsoft.CrmSdk.XrmTooling.CoreAssembly/ includes the Connector which is what I think you actually need.

You can add it to your project using the following command in your NuGet console

Install-Package Microsoft.CrmSdk.XrmTooling.CoreAssembly -Version 9.0.0.7

If you don't need a specific version you can just use

Install-Package Microsoft.CrmSdk.XrmTooling.CoreAssembly
0
votes

I generally use CrmServiceClient in the Xrm.Tooling.Connector namespace, with a connection string.

var svc = new CrmServiceClient(connectionString);

Please note that CrmServiceClient has a boolean property called IsReady, which is a good way to check if it's in a proper state.

Here are example connection strings for the various environment types. These are hardcoded examples, but you can also add them to the App.Config as shown in my answer here.

CRM 2016 and Dynamics 365 online:

var connectionString = "Url=https://dev26.crm.dynamics.com; [email protected]; Password=Pass; AuthType=Office365";

On-premise with integrated security:

var connectionString="Url=http://myserver/AdventureWorksCycle;";

On-premise with credentials:

var connectionString="Url=http://myserver/AdventureWorksCycle; Domain=mydomain; Username=administrator; Password=password; AuthType=AD;";

On-premise IFD before CRM 2016:

var connectionString="Url=https://contoso.litware.com; [email protected]; Password=password; AuthType=IFD;";

On-premise IFD for CRM 2016 and later (v8.0+)

var connectionString="ServiceUri=https://contoso.litware.com/contoso; Domain=contoso; Username=contoso\administrator; Password=password; AuthType=IFD; LoginPrompt=Never;";`