0

有没有办法在插件上创建一个 OrganizationServiceProxy 实例?
我想执行 EnableProxyTypes 方法,传递一个不同于插件程序集的程序集作为 EnableProxyTypes 方法的参数。
因为我想拥有一个具有早期绑定类并由一些插件和程序共享的程序集文件。

    public void Execute(IServiceProvider serviceProvider)
    {
        var context = (IPluginExecutionContext) serviceProvider.GetService(typeof    (IPluginExecutionContext));
        var factory = (IOrganizationServiceFactory) serviceProvider.GetService(typeof (IOrganizationServiceFactory));
        var service = factory.CreateOrganizationService(context.UserId);

        var proxy = (OrganizationServiceProxy)service; //this doesn't work. an error occurs.
    }
4

1 回答 1

0

我建议阅读这篇文章:

演练:使用开发人员扩展构建连接到 Microsoft Dynamics CRM 的插件

特别是以下片段。

IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

...

using (var crm = new XrmServiceContext(service))
于 2013-04-04T22:39:34.467 回答