2013-02-22 118 views

回答

0

來自我的一個項目的工作示例。 我不確定它是否能在WP8上工作,但在桌面上一切正常。

這是服務類。

internal class PermissiveCertificatePolicy 
{ 
    private string _subjectName; 
    private static PermissiveCertificatePolicy _currentPolicy; 

    public PermissiveCertificatePolicy(string subjectName) 
    { 
     _subjectName = subjectName; 
     ServicePointManager.ServerCertificateValidationCallback += RemoteCertValidate; 
    } 

    public static void Enact(string subjectName) 
    { 
     _currentPolicy = new PermissiveCertificatePolicy(subjectName); 
    } 

    private bool RemoteCertValidate(object sender, X509Certificate cert, 
     X509Chain chain, SslPolicyErrors error) 
    { 
     return cert.Subject == _subjectName; 
    } 
} 

下面是使用的例子:

namespace WcfClient 
{ 
    internal class Program 
    { 
     private const string RCertName = "CN=WMSvc-WIN-R0NU6K5QG87"; 

     private static void Main(string[] args) 
     { 
      PermissiveCertificatePolicy.Enact(RCertName); 

      using (MyClient proxy = new MyClient("Ws2007HttpBinding_IHistory")) 
      { 
       ... 
      } 
     } 
    } 
} 
+0

謝謝您的幫助。我擔心ServicePointManager不適用於WP8。 – MPeli 2013-02-22 16:50:34

+0

您是否找到解決方案? – 2013-03-17 12:29:33