473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Webclient failing with SSL

Ron
I have this code in a web service:

m_webclient = New WebClient

Dim byteArray As Byte()

byteArray = m_webclient.DownloadData(url)

and this has worked for quite a while. But recently, my company added SSL to
the server and now, I get the error message, "Underlying connection was
closed. Unable to connec to remote server."

It seems as if SSL is the culprit. This code is executed from client
machines. I have the feeling I need to do something like

Dim mySP As ServicePoint =
ServicePointManager.FindServicePoint(url.ToString( ))
Dim policy As MyPolicy
ServicePointManager.CertificatePolicy() = New MyPolicy

(I know this code is wrong, but I'm hoping it's not too wrong. MyPolicy is
this class:
Public Class MyPolicy
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
'Return True to force the certificate to be accepted.
Return True
End Function
Public Function AcceptAllCertificatePolicy() As Boolean
Return True
End Function
End Class

====================

Any help is obviously gratefully and nearly eternally appreciated.

RON
Jul 21 '05 #1
4 7407
Ron wrote:
I have this code in a web service:

m_webclient = New WebClient

Dim byteArray As Byte()

byteArray = m_webclient.DownloadData(url)

and this has worked for quite a while. But recently, my company added
SSL to the server and now, I get the error message, "Underlying
connection was closed. Unable to connec to remote server."

It seems as if SSL is the culprit. This code is executed from client
machines. I have the feeling I need to do something like

Dim mySP As ServicePoint =
ServicePointManager.FindServicePoint(url.ToString( ))
Dim policy As MyPolicy
ServicePointManager.CertificatePolicy() = New MyPolicy


[...]

You're on the right track. Although you shouldn't use an "Accept All"
certificate policy in production, it will definitely show if this works at
all.

Cheers,
--
Joerg Jooss
jo*********@gmx.net
Jul 21 '05 #2
Ron wrote:
Thanks for the heads up, but two questions:

Could you help me adjust the track? This didn't work (yet). Are there
any code snippets to cut and paste?

Also, this code is only executed from a very protected enviornment,
from behind a firewall and only after the user has logged in (via
calls through Oblix to LDAP), so it seems rather protected. Under
this circumstance, is AcceptAll still appropriate? And if not, how
would I modify that?


Well, you have to check why the certificate is being rejected by the .NET
FCL default policy. The default policy only accepts both valid and valid but
expired certificates. So there seems to be something wrong with that
certificate in the first place. Why use such a certificate in a production
environment?

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Jul 21 '05 #3
Ron
The cert is brand new and fully tested. This is the first time any problem
have arisen, so that line of reasoning is not correct.

Also, I do not understand the mechanism involved. When I force a false
return value in both methods in my Policy class, the connection is still OK
and the cert is accepted. I have not been able to single step through the
Policy class (which just implements ICertificatePolicy). Tthat is to say, I
don't know what triggers these functions, but it seems that the mere
existence of this class object, a non-null object value for
ServicePointManager.CertificatePolicy() is sufficient for all certs to be
automatically accepted.

Or...perhaps, since I am running in design mode, some things are cached?

RON

"Joerg Jooss" wrote:
Ron wrote:
Thanks for the heads up, but two questions:

Could you help me adjust the track? This didn't work (yet). Are there
any code snippets to cut and paste?

Also, this code is only executed from a very protected enviornment,
from behind a firewall and only after the user has logged in (via
calls through Oblix to LDAP), so it seems rather protected. Under
this circumstance, is AcceptAll still appropriate? And if not, how
would I modify that?


Well, you have to check why the certificate is being rejected by the .NET
FCL default policy. The default policy only accepts both valid and valid but
expired certificates. So there seems to be something wrong with that
certificate in the first place. Why use such a certificate in a production
environment?

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Jul 21 '05 #4
Ron wrote:
The cert is brand new and fully tested. This is the first time any
problem have arisen, so that line of reasoning is not correct.
So if you're accessing the site with a browser, it does not issue a warning?
Also, I do not understand the mechanism involved. When I force a false
return value in both methods in my Policy class, the connection is
still OK and the cert is accepted.
Weird... um... ICertifictaePolicy has only one method
CheckValidationResult(). What do you mean by "both" methods?
I have not been able to single
step through the Policy class (which just implements
ICertificatePolicy). Tthat is to say, I don't know what triggers
these functions, but it seems that the mere existence of this class
object, a non-null object value for
ServicePointManager.CertificatePolicy() is sufficient for all certs
to be automatically accepted.


Yes, that's how you set it. You should be able to put a breakpoint in there
and debug it.

Cheers,
--
Joerg Jooss
jo*********@gmx.net

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: xzzy | last post by:
I have .net 1.1 c# . . . . . using System.Net only lists sockets what do I need to do to be able to do: using System.Net.WebClient;
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
1
by: WebSLS | last post by:
I need to scrap a web page from another site but when I try to access any site outside of my localhost, I get this error: "System.Net.WebException: The underlying connection was closed: Unable to...
6
by: Dave Starman | last post by:
Hello, I am trying to download web data into my current application. Failing many attempts I tried to run the sample from the MS Help files with no luck. If I create a new solution and put the...
4
by: Ron | last post by:
I have this code in a web service: m_webclient = New WebClient Dim byteArray As Byte() byteArray = m_webclient.DownloadData(url) and this has worked for quite a while. But recently, my...
6
by: Giovanni | last post by:
Hi Guys, Really strange problem I am experiencing... I have setup a virtual directory with Read Only permissions on an ISA/IIS server (SBS 2003). In that virt. dir., I placed 1 file...
1
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config...
1
by: Mike | last post by:
I am using PowerShell to download an XML file into a string using the DownloadString(URI) method of System.Net.WebClient object. Sample commands below: $Result = $Null; $WebClient = new-object...
2
by: MichaelSchoeler | last post by:
Hi, I'm having problems with the WebClient class regarding UTF-8 encoded data. When I access a specific webservice directly I can see the data arrives in corretly formatted UTF-8. But when I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.