CRM 2011在线插件操作-如何创建OrganizationServiceProxy?
我正在尝试创建一个插件,该插件创建一个任务来响应自定义实体的创建消息。
我使用 CrmSvcUtil.exe 生成自定义 OrganizationServiceContext,我有一个控制台应用程序测试主机,它成功地使用它来创建任务(尽管使用 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);
有人能指出我正确的方向吗?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
CustomContext
应接受Microsoft.Xrm.Sdk.IOrganizationService
类型的参数。像这样(crmsvcutil生成的文件的摘录)您可以(并且应该)在插件上下文的帮助下简单地生成连接
根据您使用的
{theuri}
的值,我假设您的请求被沙箱阻止,因为它违反了其约束。Your
CustomContext
should 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.