473,287 Members | 1,650 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,287 software developers and data experts.

HTTPWebRequest Error (0x80090300) after a while

I have a vb.net service running under a Domain account. I'm trying to call a
web service on our Mainframe (IBM CICS via SSL and Client Certificates) and
after a while (1 or 2 days.. thousands of transactions) I'm getting the
following errors:
First, 2 of these:
SoapDriver GotRequestStream System.Net.WebException: The underlying
connection was closed: Could not establish secure channel for SSL/TLS. --->
System.ComponentModel.Win32Exception: Unknown error (0x80090300)
at System.Net.SSPIWrapper.AcquireCredentialsHandle(SS PIInterface
SecModule, String package, CredentialUse intent, SChannelCred scc)
at System.Net.SecureChannel.AcquireCredentials(Boolea n
beforeServerConnection)
at System.Net.SecureChannel.NextMessage(Byte[] incoming)
at System.Net.TlsStream.Handshake(ProtocolToken message)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult)
at MyApp.SoapDriver.GotRequestStream(IAsyncResult IR)
then, consistently I get this message at EndGetRequestStream for every
request:
SoapDriver GotRequestStream System.Net.WebException: The underlying
connection was closed: Could not establish secure channel for SSL/TLS. --->
System.ComponentModel.Win32Exception: Unknown error (0x80090300)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult)
at CTI_Server.SoapDriver.GotRequestStream(IAsyncResul t IR)

If I stop and restart the service, it works fine. I've heard of overloading
ICertificatePolicy but this seems like a cop-out and also unnecessary
because It works for so many transactions beforehand. Before each call from
any class, I set the object = new SoapDriver to make sure everything is
clean. I can see the connections opening on CICS but they close almost
instantaneously and we cannot find any errors on CICS. Thanks ahead of
time!! Below is all the pertinant code in the class. Transaction is
initiated by calling SendSoap sub. I've been told to use HTTP1.0 and no
keepalives. I'm to the point now I think there must be some kind of bug or
leak in the framework....

- Kevin Landymore

#Region "Imports"
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Data
Imports Microsoft.Web.Services
Imports System.Runtime.InteropServices
#End Region
Public Class SoapDriver
#Region "Events"
Public Event SoapResponse(ByVal env As SoapEnvelope)
#End Region
#Region "Structures"
Structure strucWebReqAndID
Public WebRequest As HttpWebRequest
Public RequestStream As Stream
Public RequestEnvelope As SoapEnvelope
Public ContactID As Guid
End Structure
#End Region
#Region "Declares"
Dim Store As New
Microsoft.Web.Services.Security.X509.X509Certifica teStore(Security.X509.X509
CertificateStore.StoreProvider.System,
Security.X509.X509CertificateStore.StoreLocation.C urrentUser, Store.MyStore)
Dim SPM As ServicePointManager
Dim MySP As ServicePoint
Dim MyURI As New Uri(CICS_URL)
#End Region
#Region "Functions"
Sub New()
Try
SPM.CheckCertificateRevocationList = False
SPM.DefaultConnectionLimit = 10
SPM.Expect100Continue = False
SPM.MaxServicePointIdleTime = 4950
SPM.UseNagleAlgorithm = True
MySP = SPM.FindServicePoint(MyURI)
MySP.MaxIdleTime = 5000
MySP.ConnectionLimit = 10
Store.Open()
Catch e As Exception
Debug.WriteLine(e.ToString)
End Try
End Sub
Sub SendSOAP(ByVal env As SoapEnvelope, ByVal ContactID As Guid)
Try
Dim CertLookupResult As Security.X509.X509CertificateCollection
CertLookupResult = Store.FindCertificateBySubjectString(Certificate_N ame)
If CertLookupResult.Count = 0 Then
Dim db1SqlCon As New SqlClient.SqlConnection
Dim db1SqlCmd As New SqlClient.SqlCommand
db1SqlCon.ConnectionString = DB_Connect_String
db1SqlCon.Open()
db1SqlCmd.Connection = db1SqlCon
db1SqlCmd.CommandType = CommandType.Text
db1SqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver NO CTI CERTIFICATE!')"
db1SqlCmd.ExecuteNonQuery()
db1SqlCmd.Dispose()
db1SqlCon.Close()
db1SqlCon.Dispose()
GC.Collect()
Exit Sub
End If
Dim ReqData As strucWebReqAndID
Dim HTTPPost As HttpWebRequest
HTTPPost = HttpWebRequest.Create(CICS_URL)
HTTPPost.Method = "POST"
HTTPPost.ContentType = "text/xml"
HTTPPost.Timeout = 6000
HTTPPost.ProtocolVersion = HttpVersion.Version10
HTTPPost.KeepAlive = False
HTTPPost.ClientCertificates.Add(CertLookupResult.I tem(0))
ReqData.RequestEnvelope = env
ReqData.WebRequest = HTTPPost
ReqData.ContactID = ContactID
HTTPPost.BeginGetRequestStream(AddressOf GotRequestStream, ReqData)
GC.Collect()
Catch e As Exception
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver SendSOAP" & e.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbSqlCmd.Dispose()
dbSqlCon.Close()
dbSqlCon.Dispose()
End Try
End Sub
Sub GotRequestStream(ByVal IR As IAsyncResult)
Try
Dim ReqData As strucWebReqAndID = IR.AsyncState
Dim ReqStream As Stream = ReqData.WebRequest.EndGetRequestStream(IR)
ReqData.RequestStream = ReqStream
Dim rEncode As Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")
Dim ReqWriter As New StreamWriter(ReqStream, rEncode)
ReqWriter.Write(ReqData.RequestEnvelope.OuterXml)
ReqWriter.Close()
ReqData.WebRequest.BeginGetResponse(AddressOf GotResponse, ReqData)
Catch ex As Exception
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotRequestStream " & ex.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbSqlCmd.Dispose()
dbSqlCon.Close()
dbSqlCon.Dispose()
End Try
End Sub
Sub GotResponse(ByVal IR As IAsyncResult)
Dim RespString As String
Try
Dim ReqData As strucWebReqAndID
ReqData = IR.AsyncState
Dim HTTPResp As HttpWebResponse
HTTPResp = ReqData.WebRequest.EndGetResponse(IR)
Dim RespStream As Stream = HTTPResp.GetResponseStream
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(RespStream, encode)
RespString = readStream.ReadToEnd
HTTPResp.Close()
Dim Replacer As RegularExpressions.Regex
RespString = Replacer.Replace(RespString, "&", "+")
Dim SoapResp As New SoapEnvelope
SoapResp.LoadXml(RespString)
RaiseEvent ProfileResponse(ParseSoapProfileResponse(SoapResp) ,
ReqData.ContactID)
Catch e As WebException
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotRespone WebException " & e.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbsqlcmd.Dispose()
dbSqlCon.Close()
dbsqlcon.Dispose()
Catch e As Exception
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotResponse " & e.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotResponse String Was " & RespString & "')"
dbSqlCmd.ExecuteNonQuery()
dbsqlcmd.Dispose()
dbSqlCon.Close()
dbsqlcon.Dispose()
End Try
End Sub
#End Region
End Class
Nov 20 '05 #1
1 4068
Sorry... I get the exception at the Async EndGetRequestStream call. Thanks
again!!

-Kevin Landymore
"Kevin Landymore" <kl************@sempraNOutilitiesSPAM.com> wrote in
message news:eO**************@tk2msftngp13.phx.gbl...
I have a vb.net service running under a Domain account. I'm trying to call a web service on our Mainframe (IBM CICS via SSL and Client Certificates) and after a while (1 or 2 days.. thousands of transactions) I'm getting the
following errors:
First, 2 of these:
SoapDriver GotRequestStream System.Net.WebException: The underlying
connection was closed: Could not establish secure channel for SSL/TLS. ---> System.ComponentModel.Win32Exception: Unknown error (0x80090300)
at System.Net.SSPIWrapper.AcquireCredentialsHandle(SS PIInterface
SecModule, String package, CredentialUse intent, SChannelCred scc)
at System.Net.SecureChannel.AcquireCredentials(Boolea n
beforeServerConnection)
at System.Net.SecureChannel.NextMessage(Byte[] incoming)
at System.Net.TlsStream.Handshake(ProtocolToken message)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult)
at MyApp.SoapDriver.GotRequestStream(IAsyncResult IR)
then, consistently I get this message at EndGetRequestStream for every
request:
SoapDriver GotRequestStream System.Net.WebException: The underlying
connection was closed: Could not establish secure channel for SSL/TLS. ---> System.ComponentModel.Win32Exception: Unknown error (0x80090300)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetRequestStream(IAsy ncResult
asyncResult)
at CTI_Server.SoapDriver.GotRequestStream(IAsyncResul t IR)

If I stop and restart the service, it works fine. I've heard of overloading ICertificatePolicy but this seems like a cop-out and also unnecessary
because It works for so many transactions beforehand. Before each call from any class, I set the object = new SoapDriver to make sure everything is
clean. I can see the connections opening on CICS but they close almost
instantaneously and we cannot find any errors on CICS. Thanks ahead of
time!! Below is all the pertinant code in the class. Transaction is
initiated by calling SendSoap sub. I've been told to use HTTP1.0 and no
keepalives. I'm to the point now I think there must be some kind of bug or
leak in the framework....

- Kevin Landymore

#Region "Imports"
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Data
Imports Microsoft.Web.Services
Imports System.Runtime.InteropServices
#End Region
Public Class SoapDriver
#Region "Events"
Public Event SoapResponse(ByVal env As SoapEnvelope)
#End Region
#Region "Structures"
Structure strucWebReqAndID
Public WebRequest As HttpWebRequest
Public RequestStream As Stream
Public RequestEnvelope As SoapEnvelope
Public ContactID As Guid
End Structure
#End Region
#Region "Declares"
Dim Store As New
Microsoft.Web.Services.Security.X509.X509Certifica teStore(Security.X509.X509 CertificateStore.StoreProvider.System,
Security.X509.X509CertificateStore.StoreLocation.C urrentUser, Store.MyStore) Dim SPM As ServicePointManager
Dim MySP As ServicePoint
Dim MyURI As New Uri(CICS_URL)
#End Region
#Region "Functions"
Sub New()
Try
SPM.CheckCertificateRevocationList = False
SPM.DefaultConnectionLimit = 10
SPM.Expect100Continue = False
SPM.MaxServicePointIdleTime = 4950
SPM.UseNagleAlgorithm = True
MySP = SPM.FindServicePoint(MyURI)
MySP.MaxIdleTime = 5000
MySP.ConnectionLimit = 10
Store.Open()
Catch e As Exception
Debug.WriteLine(e.ToString)
End Try
End Sub
Sub SendSOAP(ByVal env As SoapEnvelope, ByVal ContactID As Guid)
Try
Dim CertLookupResult As Security.X509.X509CertificateCollection
CertLookupResult = Store.FindCertificateBySubjectString(Certificate_N ame)
If CertLookupResult.Count = 0 Then
Dim db1SqlCon As New SqlClient.SqlConnection
Dim db1SqlCmd As New SqlClient.SqlCommand
db1SqlCon.ConnectionString = DB_Connect_String
db1SqlCon.Open()
db1SqlCmd.Connection = db1SqlCon
db1SqlCmd.CommandType = CommandType.Text
db1SqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver NO CTI CERTIFICATE!')"
db1SqlCmd.ExecuteNonQuery()
db1SqlCmd.Dispose()
db1SqlCon.Close()
db1SqlCon.Dispose()
GC.Collect()
Exit Sub
End If
Dim ReqData As strucWebReqAndID
Dim HTTPPost As HttpWebRequest
HTTPPost = HttpWebRequest.Create(CICS_URL)
HTTPPost.Method = "POST"
HTTPPost.ContentType = "text/xml"
HTTPPost.Timeout = 6000
HTTPPost.ProtocolVersion = HttpVersion.Version10
HTTPPost.KeepAlive = False
HTTPPost.ClientCertificates.Add(CertLookupResult.I tem(0))
ReqData.RequestEnvelope = env
ReqData.WebRequest = HTTPPost
ReqData.ContactID = ContactID
HTTPPost.BeginGetRequestStream(AddressOf GotRequestStream, ReqData)
GC.Collect()
Catch e As Exception
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver SendSOAP" & e.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbSqlCmd.Dispose()
dbSqlCon.Close()
dbSqlCon.Dispose()
End Try
End Sub
Sub GotRequestStream(ByVal IR As IAsyncResult)
Try
Dim ReqData As strucWebReqAndID = IR.AsyncState
Dim ReqStream As Stream = ReqData.WebRequest.EndGetRequestStream(IR)
ReqData.RequestStream = ReqStream
Dim rEncode As Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")
Dim ReqWriter As New StreamWriter(ReqStream, rEncode)
ReqWriter.Write(ReqData.RequestEnvelope.OuterXml)
ReqWriter.Close()
ReqData.WebRequest.BeginGetResponse(AddressOf GotResponse, ReqData)
Catch ex As Exception
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotRequestStream " & ex.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbSqlCmd.Dispose()
dbSqlCon.Close()
dbSqlCon.Dispose()
End Try
End Sub
Sub GotResponse(ByVal IR As IAsyncResult)
Dim RespString As String
Try
Dim ReqData As strucWebReqAndID
ReqData = IR.AsyncState
Dim HTTPResp As HttpWebResponse
HTTPResp = ReqData.WebRequest.EndGetResponse(IR)
Dim RespStream As Stream = HTTPResp.GetResponseStream
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(RespStream, encode)
RespString = readStream.ReadToEnd
HTTPResp.Close()
Dim Replacer As RegularExpressions.Regex
RespString = Replacer.Replace(RespString, "&", "+")
Dim SoapResp As New SoapEnvelope
SoapResp.LoadXml(RespString)
RaiseEvent ProfileResponse(ParseSoapProfileResponse(SoapResp) ,
ReqData.ContactID)
Catch e As WebException
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotRespone WebException " & e.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbsqlcmd.Dispose()
dbSqlCon.Close()
dbsqlcon.Dispose()
Catch e As Exception
Dim dbSqlCon As New SqlClient.SqlConnection
Dim dbSqlCmd As New SqlClient.SqlCommand
dbSqlCon.ConnectionString = DB_Connect_String
dbSqlCon.Open()
dbSqlCmd.Connection = dbSqlCon
dbSqlCmd.CommandType = CommandType.Text
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotResponse " & e.ToString & "')"
dbSqlCmd.ExecuteNonQuery()
dbSqlCmd.CommandText = "Insert Into debug_Error_Log (EventDetail) Values
('SoapDriver GotResponse String Was " & RespString & "')"
dbSqlCmd.ExecuteNonQuery()
dbsqlcmd.Dispose()
dbSqlCon.Close()
dbsqlcon.Dispose()
End Try
End Sub
#End Region
End Class

Nov 20 '05 #2

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

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
1
by: Bruce Wiebe | last post by:
hi all Im having a big problem connecting to a SSL site (HSBC Bank) using httpWebRequest. what i need to do is connet to the site and pass over an xml string and read the response. Im pretty...
1
by: etantonio | last post by:
Good Morning, I need to read a web page, to do this I use the following code that works well if I choose sAddressTime = "http://www.etantonio.it/it/index.aspx" and you can see the trace...
4
by: Steven Pu | last post by:
Hi, Specifically, the website I am trying to access is, https://gmail.google.com/ I've read elsewhere that Google only uses SSL2, while .NET uses SSL3 and is not backward compatible. Is...
1
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some...
6
by: Rachet? | last post by:
I am getting a "The remote server returned an error: (400) Bad Request." error while trying to send data to an asp page. The puzzle is, if I paste the string I want to send on a browser address...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
0
by: Alex Papadimoulis | last post by:
Hey Group, I'm in the process of converting an ASP-based site to an ASP.NET site and built a control that wraps around an ASP page. The control simply does a GET to the same server to render the...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...

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.