Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 71679

Forum Post: CRM Online 2015 Plugin gets another CRM org service error: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

$
0
0
Hi, Guys. I am building a plugin which is triggered by a creation of Account. Then the plugin will build connection and get Another CRM organization service, to create a new account as well in that CRM instance. Both CRM instances are 2015 online. And I get error when creating the second CRM proxy. The error is : System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 I did some research. Some say CRM online can not get access to external web service (in my case, call the other CRM service). Some say, CRM online can get external web service. So I am confused now. Is it possible to get another CRM web service in my current plugin? Any suggestions will be appreciated. My code: using Microsoft.Xrm.Sdk; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Metadata; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Discovery; using System.ServiceModel.Description; namespace AccountCheckPlugin { public class AccountCheck: IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); //Connect to 2nd instance ClientCredentials cre = new ClientCredentials(); trace.Trace("1"); cre.UserName.UserName = "email address"; cre.UserName.Password = "Password"; string strUrl = " xxxxxxx.api.crm.dynamics.com/.../Organization.svc "; trace.Trace("2"); Uri serviceUri = new Uri(strUrl); OrganizationServiceProxy proxy2 = new OrganizationServiceProxy(serviceUri, null, cre, null); Error occurs proxy2.EnableProxyTypes(); IOrganizationService service2 = (IOrganizationService)proxy2; trace.Trace("3"); //Connection completed trace.Trace("4"); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName == "account") { Guid account_guid = entity.Id; //Entity Account = service.Retrieve("account", account_guid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); Entity Account = new Entity("account"); Account.Attributes["name"] = "From 1st CRM org"; trace.Trace("5"); service2.Create(Account); trace.Trace("6"); } } } } }

Viewing all articles
Browse latest Browse all 71679

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>