gpt4 book ai didi

c# - 在 CRM2011 插件中创建 OrganizationServiceProxy 以使用早期绑定(bind)

转载 作者:太空狗 更新时间:2023-10-29 23:34:11 25 4
gpt4 key购买 nike

我们正在尝试在 CRM2011 插件中使用早期绑定(bind)类型。要启用此功能,我们似乎需要添加 ProxyTypesBeavior(),或调用 EnableProxyTypes()。但是,这两个属性都适用于 OrganizationServiceProxy 类,并且不存在于 IOrganizationService 接口(interface)上。

因此,如果我们使用以下代码来获取组织服务,我们将如何获取代理类来设置上述属性?

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

最佳答案

对于那些使用 CRM Online 的人来说,反射解决方案将不起作用,因为您陷入了沙盒模式。

以下使用 IProxyTypesAssemblyProvider 接口(interface)的解决方案(由 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);

关于c# - 在 CRM2011 插件中创建 OrganizationServiceProxy 以使用早期绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com