By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,146 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,146 IT Pros & Developers. It's quick & easy.

HTTPWebRequest Error (0x80090300) after a while

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.