Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

Posted on by 80

Working on CRM 365 - Version 1612 (9.0.11.9) (DB 9.0.11.9) on-premises.

How to call HTTPS WCF web service in Plugin, plugin assembly is registered in sandbox mode. I am getting System.Security.SecurityException exception, Can somebody please provide the way to all https web service.

I have also tried after changing isolation mode to None, but getting following exception:-

{"Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}

My code is below :

BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.MaxReceivedMessageSize = Int32.MaxValue;
myBinding.Name = “basicHttpBinding”;
if (EndPoint.ToLower().Contains(“https://”))
{
//Throwing exception here – System.Security.SecurityException exception,
ServicePointManager.ServerCertificateValidationCallback  = (sendr, cert, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072 | (SecurityProtocolType)192;
myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
}
else
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
myBinding.Security.Mode = BasicHttpSecurityMode.None;
}
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endPointAddress = new EndpointAddress(EndPoint);
WebIALClient myClient = new WebIALClient(myBinding, endPointAddress)
CompanyDetailsResponse response = myClient.GetCompanyDetails(request);

Can anyone please suggest how to call the external wcf service in SSL.

Thanks

  • Shubh_K Profile Picture
    Shubh_K 80 on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Hi,

    I went through the Sample code - eax360.com/.../, it is the same which I am already using and doesn't contain have any sample for SSL Endpoint.

    Thanks

  • Shubh_K Profile Picture
    Shubh_K 80 on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Hi Gilmeyer,

    1. My server is internal so cannot validate the SSL using -  www.sslshopper.com/ssl-checker.html

    2. Getting the same exception on the shared code line also.

    {"Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."}

    Thanks

  • Suggested answer
    Gilmeyer Profile Picture
    Gilmeyer on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Also, please have a look in the following sample too eax360.com/.../

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Hi Shubh,

    Please go through the below links which states the same issue as yours:

    community.dynamics.com/.../465047

    social.microsoft.com/.../securityexception-when-calling-custom-webservice-from-crm-plugin

    I hope it will be helpful

  • Suggested answer
    Gilmeyer Profile Picture
    Gilmeyer on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Still the same message? That's strange!

    Could you please validate the certificate on your service?

    What is the output of www.sslshopper.com/ssl-checker.html=[yourservice url] ?

    or also,to see if it works, try to ignore this certificate error by adding the following code:

    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

    Thanks

  • Shubh_K Profile Picture
    Shubh_K 80 on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Thanks Gilmeyer for suggestion.

    Following the input I captured from exception getting Line7 :-

    //Message

     Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    //StackTrace

      at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

      at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)

      at System.Security.CodeAccessPermission.Demand()

      at System.Net.ServicePointManager.set_ServerCertificateValidationCallback(RemoteCertificateValidationCallback value)

      at myNamespace.Plugins.GetResponceFromCompany.CreateCompanyRequest.GetCompanyResponse(String EndPoint, String Number, Tracer tracer)

    Thanks

  • Suggested answer
    Gilmeyer Profile Picture
    Gilmeyer on at
    RE: Calling External WCF Service (using generated client) from CRM sandboxed plugin OnPremise is failing

    Hi,

    That's a generic Security Exception.

    Could you please add the below try-catch statement to your plugin, so that we can get the real exception.

                    try

                    {                   

                        // Your code

                    }

                    catch (System.Security.SecurityException secEx)

                    {

                        throw new InvalidPluginExecutionException(String.Format("An error occurred in the plug-in: {0} \n {1}.", secEx.Message, secEx.StackTrace);

                        tracingService.Trace(String.Format("Plug-in failed: {0} {1}", secEx.Message, secEx.StackTrace));

                    }

                    catch (Exception ex)

                    {

                        throw new InvalidPluginExecutionException(String.Format("An error occurred in the plug-in: {0} \n {1}.", ex.Message, ex.InnerException);

                        tracingService.Trace(String.Format("Plug-in failed: {0} {1}", ex.Message, ex.InnerException));

                    }

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans