如何在从 CRM 2011 中的 IWorkflowContext 访问的服务上启用代理类型?

发布于 2025-01-04 13:41:07 字数 839 浏览 3 评论 0原文

我有一个 C# 工作流程,我正在尝试创建一个 IOrganzationService,其中启用了代理类型,以便我可以使用我的早期绑定数据类型...

这就是我创建IOrganizationSerivce

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

但由于我没有 OrganizationServiceProxy 对象,因此我无法在服务上调用 EnableProxyTypes(),也无法使用早期绑定实体对服务进行任何创建调用失败了。

我知道我可以恢复在 app.config 中设置服务器 url、sdk 服务器 url 和组织,并使用它来创建 OrganizationServiceProxy 但似乎我应该能够只设置 EnableProxyTypes关于我已经拥有的 IOrganizationService...

更新

我相信这是 2011 年甚至 2013 年的一个错误,早已得到解决。请参阅 Jim 的答案,其中包含一个链接,说明为什么您不应在 2015 年或更新的实例中使用已接受的答案。

I have a C# workflow that I'm trying to create an IOrganzationService in that has the proxy types enabled on it so I can use my early bound data types...

This is how I'm creating the IOrganizationSerivce

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

But since I don't have an OrganizationServiceProxy object, I can't call EnableProxyTypes() on the service, and any create calls on the service using an early bound entity fails.

I know I can revert to setting the server url url, sdk server url, and organization in the app.config and use that to create an OrganizationServiceProxy but it seems like I should be able to just set the EnableProxyTypes on the IOrganizationService that I already have...

Update

I believe this was a bug in 2011 and maybe 2013 that has long since been resolved. See Jim's answer with a link as to why you should not be using the accepted answer for 2015 or newer instances.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

征﹌骨岁月お 2025-01-11 13:41:07

这是一篇旧帖子,解决很久以前就解决的问题。但此处提供的一些解决方法不受支持,并且会导致使用它们的工作流活动中断。

请参阅:删除在自定义工作流活动中使用反射的不受支持的代码

This is an old post, addressing an issue that was fixed long ago. But some of the workarounds provided here are not supported and will cause workflow activities that have used them to break.

Please see this: Remove unsupported code that uses reflection in custom workflow activities

花间憩 2025-01-11 13:41:07

为了能够在工作流上下文中使用早期绑定实体,请尝试以下代码片段:

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

var type = Type.GetType("Microsoft.Crm.Workflow.SynchronousRuntime.WorkflowContext, Microsoft.Crm.Workflow, Version=5.0.0.0");
type.GetProperty("ProxyTypesAssembly").SetValue(serviceFactory, typeof(YourServiceContext).Assembly, null); //YourServiceContext - the name of crm context
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); 

如您所见,有一个名为 ProxyTypesAssembly 的属性,它指定保留早期绑定实体的程序集。我设置此属性的唯一方法是使用反射,因为 WorkflowContextBaseWorkflowContext 的基类)无法访问。

To be able to use the early bound entities in the context of an workflow try the following snippet:

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

var type = Type.GetType("Microsoft.Crm.Workflow.SynchronousRuntime.WorkflowContext, Microsoft.Crm.Workflow, Version=5.0.0.0");
type.GetProperty("ProxyTypesAssembly").SetValue(serviceFactory, typeof(YourServiceContext).Assembly, null); //YourServiceContext - the name of crm context
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); 

As you can see there is a property named ProxyTypesAssembly that specifies the assembly where you keep the early bound entities. The only way i could set this property was using reflection because the WorkflowContextBase (the base class of WorkflowContext) was not accessible.

溺深海 2025-01-11 13:41:07

CRM 2013(以及更高版本,我希望)的修复要简单得多:

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

// this is the important change
var property = serviceFactory.GetType().GetProperty("ProxyTypesAssembly");

property.SetValue(serviceFactory, typeof(YourServiceContext).Assembly, null);
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); 

The fix for CRM 2013 (and beyond, I hope), is the much simpler:

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

// this is the important change
var property = serviceFactory.GetType().GetProperty("ProxyTypesAssembly");

property.SetValue(serviceFactory, typeof(YourServiceContext).Assembly, null);
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); 
陌若浮生 2025-01-11 13:41:07

使用反射的答案并不理想,您将无法在沙箱隔离模式下注册程序集。

您可以将以下内容添加到插件或工作流项目中的 AssemblyInfo.cs 文件末尾。

[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssembly()]

The answers using reflection are not ideal, you will not be able to register your assembly in sandbox isolation mode.

You can add the following to the end of your AssemblyInfo.cs file in the Plugin or Workflow project.

[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssembly()]
意中人 2025-01-11 13:41:07

几个月前我发现了同样的问题。
您遇到的问题是由于 api 不一致造成的。

OrganizationServiceProxy 实现了 IOrganizationService,它只有几个成员 create、update 等。它还继承自 ServiceProxy,成员有 ClientCredentials、IsAuthenticated、DeviceCredentials 等。

现在,您在接口或抽象基类中找不到的是 EnableProxyTypes 成员。

所以基本上你运气不好。我结束了使用具体的 OrganizationServiceProxy。

看看这里并自己进行比较。

http://technet.microsoft.com/en-us /library/microsoft.xrm.sdk.iorganizationservice_members.aspxhttp://technet.microsoft.com/en-us /library/microsoft.xrm.sdk.client.organizationserviceproxy.aspx, http://technet.microsoft.com/en-us/library/gg306039.aspx
http://technet.microsoft.com/ en-us/library/microsoft.xrm.sdk.client.organizationserviceproxy_methods.aspx

猜测创建 api 的 ms crm 开发团队应该使用 tdd以及一个在开发早期就可以使用的模拟框架。

干杯
拉斯廷

I found this same issue couple months back.
The issue you are experiencing is due to the inconsistencies in the api.

The OrganizationServiceProxy implements IOrganizationService which only has a few members create, update etc. It also inherits from ServiceProxy with members ClientCredentials, IsAuthenticated, DeviceCredentials etc.

Now what you don't find on the interface or the abstract base class is the EnableProxyTypes member.

So basically your outta luck. I ended using concrete OrganizationServiceProxy.

have a look here and do the comparison for yourself.

http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.iorganizationservice_members.aspx, http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.client.organizationserviceproxy.aspx, http://technet.microsoft.com/en-us/library/gg306039.aspx
and http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.client.organizationserviceproxy_methods.aspx

Guess the ms crm dev team creating the api should have used tdd and a mocking framework to pick it up early in development.

Cheers
Rustin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文