473,221 Members | 1,590 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,221 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 4330
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Wild Wind | last post by:
Hello all, I apologise in advance for the long windedness of this post, but I feel that if I am going to get any solution to this problem, it is important that I present as much information...
1
by: Fredrik L | last post by:
Hi, We have an application outside the firewall who talks to a webservice inside the firewall. 9 times of 10 this works, but sometimes we got the error "The underlying connection was closed: An...
0
by: Ahmad Atawneh | last post by:
I have the following problem: i have a client (windows service) calling a web service using an 128kbps connection line. The client will frequently send records of approximately 300KB to the web...
0
by: lpinho | last post by:
Hi There, I've generated a C# file from a wsdl file using wsdl.exe utility. Then I created a console application and made a call to the method generated, first I got the error: "The request...
4
by: Matthew.DelVecchio | last post by:
hello, i am developing an ASP.NET web app that consumes a 3rd party vendor webservice. it is my first one so while ive done my homework, im not an expert on the matter. our partner's...
1
by: Mrozik | last post by:
Hi! I have a problem - after deploying application in client environment, on some client machines occured error. Environment: App server: ASP.NET WebService/Win 2003/ secured SSL (.NET 2.0)...
0
by: =?Utf-8?B?VGFoYQ==?= | last post by:
I am working on a C#.Net application that consumes a web service developped (by others) in Java. My application calls a web method to post a 64-bit binary file to the web service. The...
1
by: Gx3r0 | last post by:
0I have a windows service I created that checks for data to post to an off site webservice over SSL. The service checks every 10 seconds for data to send, if there is data it opens a connection to...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.