2009-08-26 57 views
0

最近,我們的網站託管服務提供商移動到所有共享ASP.NET網站託管的中等信任級別。因此,我們在通過PayPal的SOAP API完成交易時遇到了一些問題。具體而言,一個SecurityException異常被拋出與以下堆棧跟蹤:貝寶 - ASP.NET中等信託

[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 
... 

我找到了源於貝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 

是否有知道什麼變化率(s)需要作出允許SDK在中等信任環境中發揮作用?是否有必要接受所有不可信任的證書?

謝謝。

回答

1

您可以向您的ISP詢問GAC PayPal程序集 - 這樣它們以完全信任的方式運行(假設它們在程序集上設置了允許部分信任的調用程序屬性)。

中等信任的其他問題是它不允許傳出網絡連接,包括SOAP調用。

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; 
} 

托馬斯