Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to EnableProxyTypes on a service accessed from the IWorkflowContext in CRM 2011?

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.

like image 200
Daryl Avatar asked Jan 27 '26 12:01

Daryl


1 Answers

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

like image 153
Jim Daly -MSFT- Avatar answered Jan 29 '26 05:01

Jim Daly -MSFT-