最近,我们的Web托管服务提供商转移到所有共享ASP.NET站点托管的中等信任级别。因此,我们在通过PayPal的SOAP API完成交易时遇到了一些问题。具体来说,使用以下堆栈跟踪抛出SecurityException异常:
[SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +58
System.Net.ServicePointManager.set_CertificatePolicy(ICertificatePolicy value) +54
com.paypal.sdk.core.APICallerBase.SetTrustManager() +30
com.paypal.sdk.core.soap.SOAPAPICaller..ctor() +14
com.paypal.sdk.services.CallerServices..ctor() +23
...
我在PayPal SOAP SDK中找到了违规方法的来源。
/// <summary>
/// To Accept all un-trusted certificate
/// </summary>
private void SetTrustManager()
{
//This code is added to accept all un-trusted certificate i.e self-signed certificate
if (Config.Instance.TrustAll)
{
//ServicePointManager.CertificatePolicy = TrustAllCertificatePolicy.Instance;
ServicePointManager.CertificatePolicy = new MyPolicy();
}
} // SetTrustManager
是否有人知道需要做出哪些更改才能让SDK在中等信任环境中运行?是否必须接受所有不受信任的证书?
感谢。
答案 0 :(得分:1)
您可以向您的ISP咨询GAC PayPal程序集 - 这样他们就可以完全信任(假设他们在程序集上设置了允许部分信任的调用者属性)。
您对Medium Trust的另一个问题是它不允许传出网络连接,包括SOAP调用。
答案 1 :(得分:1)
我的问题是阅读配置文件
替换
public static Dictionary<string, string> GetConfig()
{
return PayPal.Api.ConfigManager.Instance.GetProperties();
}
public static Dictionary<string, string> GetConfig()
{
var dict = new Dictionary<string, string>();
dict["mode"] = "sandbox";
dict["connectionTimeout"] = "360000";
dict["requestRetries"] = "1";
dict["clientId"] = "AXRCZ.....-NJ1asp";
dict["clientSecret"] = "EFQC....x5tqD14-tf";
return dict;
}
托马斯