web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Gilmeyer Profile Picture
    on at

    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

  • Shubh_K Profile Picture
    80 on at

    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
    on at

    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

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    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
    on at

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

  • Shubh_K Profile Picture
    80 on at

    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

  • Shubh_K Profile Picture
    80 on at

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans