Calling Web Services serverd with Self-Signed Certificates
Chris Salek wrote in one of the newsgroups I'm watching (sorry, I've missplaced the posting.) Since this wasn't exactly easy to find, I'm posting my response and code here too.
...Runs without error, but any attempt to call a function after this results in an 'Access Denied' error. [The same username and password works fine from the java client they supplied]...
He's working against a Java Service using Axis. Sounds like a part of the problem I ran into a couple of days ago. Basically, if their certificate is self-issued/self-signed, you're going to have to override .NET's certificate acceptance policy. First, you'll want to create a class like this in your project:
Public Class OverrideCertificatePolicy
Implements ICertificatePolicy
Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, _
ByVal cert As X509Certificate, ByVal request As WebRequest, _
ByVal certificateProblem As Integer) _
As Boolean Implements ICertificatePolicy.CheckValidationResult
If cert.GetRawCertDataString = ConfigurationSettings.AppSettings("vendorCertValid") Then
Return True
Else
Return False
End If
End Function
End Class
Then at somepoint before you call the WebService, you'll need to do this:
System.Net.ServicePointManager.CertificatePolicy = New OverrideCertificatePolicy
That *should* help, but its not exactly the safest of code to write since it by-passes a fairly essential element in the SSL exchange. That's why I'm doing the GetRawCertDataString comparsion against a known good value for it.