1
votes

I am trying to call a Web API endpoint(https) using client certificate in Dynamics CRM plugin on Sandbox environment and I am getting the following error message.

Unhandled Exception: 
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unexpected exception from plug-in (Execute): MyTestPlugin.PatchOnRevise: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.KeyContainerPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.Detail: 
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ActivityId>9eb9f246-31da-42d4-a8ad-a93b16c783d7</ActivityId>
  <ErrorCode>-2147220956</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
  <Message>Unexpected exception from plug-in (Execute): MyTestPlugin.PatchOnRevise: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.KeyContainerPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.</Message>
  <Timestamp>2018-07-08T22:01:17.969528Z</Timestamp>
  <ExceptionRetriable>false</ExceptionRetriable>
  <ExceptionSource i:nil="true" />
  <InnerFault i:nil="true" />
  <OriginalException i:nil="true" />
  <TraceText>

This is the code wherein I am attaching the certificate to WebClient.

protected override WebRequest GetWebRequest(Uri _address)
        {
            X509Certificate2 x509Certificate2 = new X509Certificate2(_bytes);
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(_address);
            request.ClientCertificates.Add(x509Certificate2);
            return request;
        }

I have tried to disable Sandbox, but no luck. Is there anything else I need to do to fix this issue.

1

1 Answers

1
votes

You can't disable sandbox in an online environment.

I suspect the issue is related to this, I'm not sure if certificate based security is supported.

Plug-in isolation, trusts, and statistics

Web access

Sandboxed plug-ins and custom workflow activities can access the network through the HTTP and HTTPS protocols. This capability provides support for accessing popular web resources like social sites, news feeds, web services, and more. The following web access restrictions apply to this sandbox capability.

  • Only the HTTP and HTTPS protocols are allowed.

  • Access to localhost (loopback) is not permitted.

  • IP addresses cannot be used. You must use a named web address that requires DNS name resolution.

  • Anonymous authentication is supported and recommended. There is no provision for prompting the logged on user for credentials or saving those credentials.