【问题标题】:WP8, Consuming SOAP with self-signed certificateWP8,使用带有自签名证书的 SOAP
【发布时间】:2013-02-22 15:33:44
【问题描述】:

我能够通过 SOAP 使用 Web 服务。但是,我想使用带有自签名证书的 https 连接。

如何强制我的应用使用我的证书?我能够使用 Android 实现the same thing

谢谢你,马丁。

【问题讨论】:

    标签: c# soap certificate windows-phone-8 self-signed


    【解决方案1】:

    我的一个项目中的一个工作示例。 我不确定它是否可以在 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"))
                {
                    ...
                }
            }
        }
    }
    

    【讨论】:

    • 感谢您的帮助。恐怕 ServicePointManager 不适用于 WP8。
    • 您找到解决方案了吗?
    猜你喜欢
    • 2015-02-21
    • 2013-07-08
    • 2014-05-05
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多