3
我試圖連接到Exchange Web服務以代表用戶通過我自己的Web服務(ASP/WCF)發送電子郵件。我的代碼在桌面PC上運行時可以正常連接到交換服務器,但在互聯網上運行交換服務器時無法訪問,因此我試圖通過Web服務器進行連接。交換Web服務x509證書
我尋找各種方法來登錄,其他用戶不使用Exchange Web服務模擬(因爲我已經被告知不要使用,除非有絕對沒有其他的方式),並沒有向用戶提供他們的密碼。
我有以下代碼:
Dim service As New Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2007_SP1)
Dim emailAddress As String = "[email protected]"
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服務進行身份驗證,而不是使用網絡憑證或用戶名/密碼