我们正在尝试在CRM2011插件中使用早期绑定类型。要实现这一点,我们似乎需要添加一个ProxyTypesBeavior(),或者调用EnableProxyTypes()。但是,这两个属性都适用于OrganizationServiceProxy类,并且在IOrganizationService接口上不存在。
那么,如果我们使用下面的代码来获取组织服务,那么我们如何获得一个代理类来设置上面的属性呢?
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);发布于 2014-02-26 03:17:11
对于那些使用CRM Online的人来说,反射解决方案将无法工作,因为您被困在沙盒模式中。
以下使用IProxyTypesAssemblyProvider接口的解决方案(由Pavel Korsukov建议)适用于我(source)。
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var proxyTypesProvider = factory as IProxyTypesAssemblyProvider;
if (proxyTypesProvider != null)
{
proxyTypesProvider.ProxyTypesAssembly = typeof(Xrm.XrmServiceContext).Assembly;
}
// Use the factory to generate the Organization Service.
var service = factory.CreateOrganizationService(context.UserId);发布于 2012-10-12 05:36:31
此线程上的Guil提供了使用反射将代码生成代理类型绑定到服务工厂的选项。这对我很管用。无法在沙箱中注册它,因为反射需要完全信任。
factory.GetType().GetProperty("ProxyTypesAssembly").SetValue(factory, typeof(YourCrmContext).Assembly, null);http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/bc7e93d4-1b36-4e21-9449-f51b67a2e52c/
发布于 2012-03-23 15:16:12
像这样写,
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);https://stackoverflow.com/questions/6490760
复制相似问题