我正在尝试创建一个插件,该插件创建一个任务以响应自定义实体的创建消息。
我已使用 CrmSvcUtil.exe 生成自定义 OrganisationServiceContext,我有一个控制台应用程序测试主机,它成功地使用它来创建任务(尽管使用 SDK serverConnect.GetServerConfiguration() 来创建 OrganizationServiceProxy)。
当我将插件程序集(沙盒)部署到在线实例时,下面的代码会爆炸:
System.Security.SecurityException:请求“System.Security.Permissions.SecurityPermission,mscorlib,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089”类型的权限失败
// 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);
有人可以指出我正确的方向吗?
谢谢