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
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
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
Also, please have a look in the following sample too eax360.com/.../
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
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
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
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
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156