I have a web client application built on .Net Frameworks 2.0 that connects to
a web service on IIS 6.0 via SSL and using X509 Client Certificates. At some
locations (it works at others), I get the following error. Below is my code.
I've also used System.Net.Tracing and have the traffic generated as a result
of the web request if anyone wants to view it.
System.Net.WebException: There was an error downloading
'https://web-site-url/web-service.asmx'. ---> System.Net.WebException: The
underlying connection was closed: An unexpected error occurred on a send.
---> System.IO.IOException: The handshake failed due to an unexpected packet
format.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32
readBytes, AsyncProtocolRequest asyncRequest)
... remainder ommitted for brevity.
THE CODE:
' Connect to Web Service
Dim metwebProxy As New CalAuthWs
Dim userProxy As IWebProxy
' Set certificate policy to ignore metweb certificate error notifications
ServicePointManager.ServerCertificateValidationCallback =
g_certificateValidationCallback
metwebProxy.PreAuthenticate = True
' Set Network Proxy Server depending on user selections
If String.Compare(My.Settings.UserProxy, m_PROXY_DEFAULT, True) = 0 Then
....userProxy = WebRequest.DefaultWebProxy
....If Not userProxy Is Nothing Then
........If My.Settings.UseDefaultCredentials Then
............userProxy.Credentials = CredentialCache.DefaultCredentials
........End If
........metwebProxy.Proxy = userProxy
....End If
ElseIf String.Compare(My.Settings.UserProxy, m_PROXY_USER_DEFINED, True) = 0
Then
....' User has manual proxy server settings
....userProxy = Utilities.GetUserProxyServer
....If Not userProxy Is Nothing Then metwebProxy.Proxy = userProxy
End If
' Add client-side certificate
metwebProxy.ClientCertificates.Add(x509In)
' Test Connection
If metwebProxy.TestLogin(certificateSubject, ApplicationSource.AFCAV) Then
....Return metwebProxy
Else
....' Web Service indicates system is down
....Dim status As String = metwebProxy.ServerStatus
....DisplayMessage(True, "Access Denied: WebAFCAV is currently not
available. Status: " & status)
....Return Nothing
End If
John Saunders [MVP] - 30 Aug 2007 20:48 GMT
>I have a web client application built on .Net Frameworks 2.0 that connects
>to
[quoted text clipped - 15 lines]
> readBytes, AsyncProtocolRequest asyncRequest)
> ... remainder ommitted for brevity.
I have no idea what could be causing this, but given the
"System.Net.Security.SslState.StartReadFrame" being on the stack, this would
appear to have to do with the client and server SSL implementations failing
to talk to each other. You'd probably get better answers in a different
forum. Possibly the microsoft.public.dotnet.framework newsgroup, or the .NET
Framework Networking and Communication forum at
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=40&SiteID=1.

Signature
John Saunders [MVP]
WeluR - 30 Aug 2007 21:12 GMT
John,
I agree. There's a proxy server in the traffic and I think the initial SSL
or TCP connection is being closed during the communication with the proxy
server.
I moved my post to the .Net Framework Networking and Communication forum as
you suggested.
Ross
> I have no idea what could be causing this, but given the
> "System.Net.Security.SslState.StartReadFrame" being on the stack, this would
[quoted text clipped - 3 lines]
> Framework Networking and Communication forum at
> http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=40&SiteID=1.
Alex Meleta - 30 Aug 2007 20:52 GMT
Hi WeluR,
Try to monitor the connection by something like Microsoft Network Monitor.
Sure you will see the source of problem - you probably sent message in inappropriate
format, so, just:
- check format of sending message
- check the response
- check the WSDL format to find corresponding between it [wsdl] and sending
message
Hopefully this helps
Regards, Alex
[TechBlog] http://devkids.blogspot.com
> I have a web client application built on .Net Frameworks 2.0 that
> connects to
[quoted text clipped - 58 lines]
> ....Return Nothing
> End If
Alex Meleta - 30 Aug 2007 20:54 GMT
Hi WeluR,
Yeah, Microsoft Network Monitor 3.1, works fine even on Vista )
http://www.microsoft.com/downloads/details.aspx?familyid=18b1d59d-f4d8-4213-8d17
-2f6dde7d7aac&displaylang=en
Regards, Alex
[TechBlog] http://devkids.blogspot.com
> I have a web client application built on .Net Frameworks 2.0 that
> connects to
[quoted text clipped - 58 lines]
> ....Return Nothing
> End I
WeluR - 31 Aug 2007 13:52 GMT
Hi Alex,
Thanks for the reply. Unfortunately, I'm working with remote clients that
don't have the expertise (or install rights) to use Network Monitor (the
application works great on my machine and I can't duplicate the error
locally).
However, I have implemented System.Net.Tracing (a very neat feature BTW) and
I can see all the HTTP traffic. It appears to make two CONNECT requests to
the proxy server and then tries to resubmit the web server request via a GET.
At that point it errors out with a closed connection. Somehow, the SSL
connection is not being maintained.
Thanks,
Ross
> Hi WeluR,
>
[quoted text clipped - 66 lines]
> > ....Return Nothing
> > End If