【发布时间】:2017-07-09 04:26:52
【问题描述】:
我需要通过 CRM 365 插件连接和检索 CRM Online 中的记录。我尝试使用xrm.tooling.dll 进行简化连接,但不幸的是它显示Could not load file or assembly 'microsoft.xrm.tooling.connector,当我使用ClientCredential 时,错误显示Metadata contain refereces that cannot be resolved。
奇怪的是,我用控制台应用程序尝试了这两种方法,而且效果很好。只是想知道我在这种情况下想念什么?当我想通过插件连接到CRM时,我需要特殊要求吗?请任何人分享您的知识。
编辑
这只是一个示例代码,用于从 CRM Online 获取帐户名称并使用 InvalidPluginExecutionException 显示它:
IOrganizationService _service;
public void Execute(IServiceProvider serviceprovider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceprovider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity ent = (Entity)context.InputParameters["Target"];
if (ent.LogicalName != "opportunity")
return;
string connstring = @"Url=https://office.crm5.dynamics.com; Username=username@office.onmicrosoft.com; Password=crmoffice; authtype=Office365";
CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connstring);
service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient :
(IOrganizationService)conn.OrganizationServiceProxy;
try
{
Guid fabercastel = new Guid("efd566dc-10ff-e511-80df-c4346bdcddc1");
Entity _account = new Entity("account");
_account = service.Retrieve(_account.LogicalName, fabercastel, new ColumnSet("name"));
string x = _account["name"].ToString();
throw new InvalidPluginExecutionException("Result of Query : " + x);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
【问题讨论】:
-
您应该已经拥有在插件执行上下文中连接到 CRM 所需的上下文信息。你能出示你的代码吗?
-
@jasonscript hii,“您应该已经拥有连接到 CRM 所需的上下文信息”是什么意思?我以前从未这样做过,通常我创建控制台应用程序来从 CRM 中检索记录。我是新手,请和我一起裸露
标签: dynamics-crm-2011 dynamics-crm crm dynamics-crm-online dynamics-crm-365