473,385 Members | 1,396 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,385 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 7410
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...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.