471,582 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

VS2005 vs VS2003 Web Service Calls - The underlying connection was closed: An unexpected error occurred on a send.

I have VB code in VS2003 which creates a HttpWebRequest and performs a POST
operation to a remote URL (an https site), which runs fine and receives a
valid response.

However exactly the same code in VS2005 (to the same site with the same
data) causes an exception 'The underlying connection was closed: An
unexpected error occurred on a send.'

Any ideas as to why and what I can do to get around this?

Thanks

Andrew

Code is as follows:

Private Function PostWithResponse(ByVal URL As String, _
Optional ByVal PostData As String = "") As String

Dim Request As HttpWebRequest = WebRequest.Create(URL)
Dim Response As HttpWebResponse
Dim SW As StreamWriter
Dim SR As StreamReader
Dim ResponseData As String

' Prepare Request Object
Request.Method = "POST"

' Set Content-Type
Request.ContentType = "application/x-www-form-urlencoded"
Request.ContentLength = PostData.Length

' Send Request
Try
SW = New StreamWriter(Request.GetRequestStream())
SW.Write(PostData)
Catch Ex As Exception
Throw Ex
Finally
SW.Close()
End Try

' Receive Response
Try
Response = Request.GetResponse()
SR = New StreamReader(Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
Catch Wex As System.Net.WebException
SR = New StreamReader(Wex.Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
Throw New Exception(ResponseData)
Finally
SR.Close()
End Try

Return ResponseData

End Function
Jul 26 '06 #1
2 4223
I am intermittently getting this error as well. It is driving me nuts.
I have applied all the fixes that were specified in other posts, but it
still happens...Here is what I did to try to fix it.

1. Override the GetWebRequest method

protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest =
(HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}

2. Modify the MaxServicePointIdleTime to a value less than the
Connection timeout in IIS.
System.Net.ServicePointManager.MaxServicePointIdle Time = 10;

3. Couldn't disable keep alives on the website from within IIS.

I am still desperately trying to get a fix for this...it's killing
me...
Andrew Hunot wrote:
I have VB code in VS2003 which creates a HttpWebRequest and performs a POST
operation to a remote URL (an https site), which runs fine and receives a
valid response.

However exactly the same code in VS2005 (to the same site with the same
data) causes an exception 'The underlying connection was closed: An
unexpected error occurred on a send.'

Any ideas as to why and what I can do to get around this?

Thanks

Andrew

Code is as follows:

Private Function PostWithResponse(ByVal URL As String, _
Optional ByVal PostData As String = "") As String

Dim Request As HttpWebRequest = WebRequest.Create(URL)
Dim Response As HttpWebResponse
Dim SW As StreamWriter
Dim SR As StreamReader
Dim ResponseData As String

' Prepare Request Object
Request.Method = "POST"

' Set Content-Type
Request.ContentType = "application/x-www-form-urlencoded"
Request.ContentLength = PostData.Length

' Send Request
Try
SW = New StreamWriter(Request.GetRequestStream())
SW.Write(PostData)
Catch Ex As Exception
Throw Ex
Finally
SW.Close()
End Try

' Receive Response
Try
Response = Request.GetResponse()
SR = New StreamReader(Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
Catch Wex As System.Net.WebException
SR = New StreamReader(Wex.Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
Throw New Exception(ResponseData)
Finally
SR.Close()
End Try

Return ResponseData

End Function
Jul 27 '06 #2
Many thanks for this but unfotunately it did not make any difference.

"Beowshawitz" <ch******@gmail.comwrote in message
news:11*********************@s13g2000cwa.googlegro ups.com...
>I am intermittently getting this error as well. It is driving me nuts.
I have applied all the fixes that were specified in other posts, but it
still happens...Here is what I did to try to fix it.

1. Override the GetWebRequest method

protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest =
(HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}

2. Modify the MaxServicePointIdleTime to a value less than the
Connection timeout in IIS.
System.Net.ServicePointManager.MaxServicePointIdle Time = 10;

3. Couldn't disable keep alives on the website from within IIS.

I am still desperately trying to get a fix for this...it's killing
me...
Andrew Hunot wrote:
>I have VB code in VS2003 which creates a HttpWebRequest and performs a
POST
operation to a remote URL (an https site), which runs fine and receives a
valid response.

However exactly the same code in VS2005 (to the same site with the same
data) causes an exception 'The underlying connection was closed: An
unexpected error occurred on a send.'

Any ideas as to why and what I can do to get around this?

Thanks

Andrew

Code is as follows:

Private Function PostWithResponse(ByVal URL As String, _
Optional ByVal PostData As String = "") As String

Dim Request As HttpWebRequest = WebRequest.Create(URL)
Dim Response As HttpWebResponse
Dim SW As StreamWriter
Dim SR As StreamReader
Dim ResponseData As String

' Prepare Request Object
Request.Method = "POST"

' Set Content-Type
Request.ContentType = "application/x-www-form-urlencoded"
Request.ContentLength = PostData.Length

' Send Request
Try
SW = New StreamWriter(Request.GetRequestStream())
SW.Write(PostData)
Catch Ex As Exception
Throw Ex
Finally
SW.Close()
End Try

' Receive Response
Try
Response = Request.GetResponse()
SR = New StreamReader(Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
Catch Wex As System.Net.WebException
SR = New StreamReader(Wex.Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
Throw New Exception(ResponseData)
Finally
SR.Close()
End Try

Return ResponseData

End Function

Aug 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by =?Utf-8?B?VGFoYQ==?= | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by lumer26 | last post: by

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.