I’m trying to create a plugin which creates a task in response to the create message for a custom entity.
I’ve used CrmSvcUtil.exe to generate a custom OrganisationServiceContext, I have a console application test host which successfully uses this to create a task (although using the SDK serverConnect.GetServerConfiguration() to create the OrganizationServiceProxy).
When i deploy the plugin assembly (sandboxed) to the online instance, the code below blows up with:
System.Security.SecurityException: Request for the permission of type
‘System.Security.Permissions.SecurityPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’
failed
// Obtain the execution context from the service provider.
var executionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(executionContext.UserId);
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Buiding");
var organizationUri = new Uri("{theuri}/XRMServices/2011/Organization.svc");
var credentials = new ClientCredentials();
credentials.Windows.ClientCredential = NetworkCredential)CredentialCache.DefaultCredentials;
var organizationServiceProxy = new OrganizationServiceProxy(organizationUri, null, credentials, null);
organizationServiceProxy.EnableProxyTypes();
var context = new CustomContext(organizationServiceProxy);
Can somebody point me in the right direction?
Thanks
Your
CustomContextshould accept a parameter of typeMicrosoft.Xrm.Sdk.IOrganizationService. Like this (excerpt of a crmsvcutil generated file)You could (and should) simply generate the connection with help of the plugin context
Depending on the value of
{theuri}you are using, I assume that your request is blocked by the sandbox as it violates its constraints.