如何在插件中调用HTTPS WCF Web服务,插件程序集以沙箱模式注册。我收到System.Security.SecurityException
异常,有人可以提供通往所有https Web服务的方法。我的代码如下:
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)
由于您使用的是本地版本,因此可以在非沙盒模式下注册插件程序集。即Isolation mode = none
以克服此类错误。
[如果要使用沙箱模式,请尝试使用WebClient
类来调用WCF服务调用。 Read more
using (WebClient client = new WebClient())
{
byte[] responseBytes = client.DownloadData(webAddress);
string response = Encoding.UTF8.GetString(responseBytes);
tracingService.Trace(response);
// For demonstration purposes, throw an exception so that the response
// is shown in the trace dialog of the Microsoft Dynamics CRM user interface.
throw new InvalidPluginExecutionException("WebClientPlugin completed successfully.");
}
您可以尝试并且还包括:使用System.Web.Http.Cors;
[EnableCors(来源:“ ”,标题:“”,方法:“ *”)]
[Route(“ api / ConvertUpload / {env} / {id}”)]
公共字符串Get(字符串env,字符串id){
return "hi";
}
您可能必须使用@Arun提到的WebClient。