Enjoy Every Sandwich

Thoughts on SQL, XML, .NET and sometimes beer.

<November 2008>
SuMoTuWeThFrSa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456


Navigation

Tools

List O'Links

Kent's Other Stuff

Subscriptions

News

Please read these
Notices and Disclamiers

Post Categories

Article Categories



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.

posted on Wednesday, August 04, 2004 6:48 AM by ktegels





Powered by Dot Net Junkies, by Telligent Systems