有没有办法在插件上创建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.
}
答案 0 :(得分:0)
我建议阅读这篇文章:
Walkthrough: Build a Plug-in That Connects to Microsoft Dynamics CRM Using Developer Extensions
特别是以下片段。
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
...
using (var crm = new XrmServiceContext(service))