在 c# 控制台应用程序和 crm 之间建立连接字符串时出错

Errors in establishing connection string between c# console application and crm

我一直在尝试以下代码,但错误是:

the type and namespace named crmConnection could not be found.

var connection = new CrmConnection();
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
var connection = CrmConnection.Parse("Url=https://xyz.crm.dynamics.com;Username=username1;Password=password1);

你能帮帮我吗?

如果您还没有 CRM SDK,则需要获取它,然后添加对包含 CrmConnection.

Microsoft.Xrm.Client 程序集的引用

我使用以下方法连接到 CRM OrganizationService,因为我在 CrmConnection 和 Tooling.CrmConnector 方面遇到了问题。此方法已针对面向 Internet 的部署的本地安装进行了测试。

{OrganizationName}{Servername} 替换为 CRM 组织的名称和 CRM 服务器的 URL。例如: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);

要在 VS 项目中安装 Microsoft.Xrm.Sdk 包,请执行以下操作:

  • 在Soltion explorer中右击Solution Node,选择"Manage NuGet packages for Solution"
  • 在 NuGet 资源管理器中,选择 "Browse" 并搜索 "CRM SDK 2016"
  • 选择Microsoft.CrmSdk.CoreAssemblies、select要安装包的项目,然后点击"Install"