首页 文章

交换网络服务x509 Certivicate

提问于
浏览
3

我正在尝试连接到Exchange Web服务,以通过我自己的Web服务(ASP / WCF)代表用户发送电子邮件 . 我的代码在能够连接到交换服务器的台式PC上运行时工作正常但在通过互联网操作时无法访问交换服务器,因此我尝试通过我的Web服务器进行连接 .

我正在寻找方法作为另一个用户登录而不使用Exchange Web服务模拟(因为我被告知不使用它,除非绝对没有其他方式)并且没有用户提供他们的密码 .

我有以下代码:

Dim service As New Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2007_SP1)
Dim emailAddress As String = "example@example.com"
System.Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf CertificateValidationCallBack


Dim cert As New System.Security.Cryptography.X509Certificates.X509Certificate2(HttpContext.Current.Request.ClientCertificate.Certificate)
service.Credentials = New Microsoft.Exchange.WebServices.Data.WebCredentials(New System.Security.Cryptography.X509Certificates.X509Certificate())
service.UseDefaultCredentials = False

但由于 Unable to cast object of type 'System.Security.Cryptography.X509Certificates.X509Certificate' to type 'System.Net.ICredentials'. 异常,这不起作用 .

任何人都可以指导我如何使用X509证书对Exchange Web服务进行身份验证,而不是使用网络凭据或用户名/密码

1 回答

  • 0

    我一直在使用它没有错误

    ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
    

相关问题