Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
|
.NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Web Services section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2003, 05:22 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default The underlying connection was closed:

occasionally I recieve this error from production enviroment when asp.net call web service, the next call to web service is usually succesful. Error
System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown.

---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

   at System.Web.Services.Protocols.WebClientProtocol.Ge tWebResponse(WebRequest request)

   at System.Web.Services.Protocols.HttpWebClientProtoco l.GetWebResponse(WebRequest request)

   at System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String methodName, Object[] parameters)

   at MySite.MyService.Service1.ProcessUpdates(String ApplicationName, Boolean bUpdateAllData)

   at MySite.MyAspxPage.Sub_CommitTransaction(Object sender, EventArgs e)

   at System.Web.UI.TemplateControl.OnCommitTransaction( EventArgs e)

   at System.Web.UI.Page.ProcessRequestTransacted()

   --- End of inner exception stack trace ---

   at System.Web.UI.Page.HandleError(Exception e)

   at System.Web.UI.Page.ProcessRequestTransacted()

Anyone else had this problem?
 
Old October 9th, 2003, 06:12 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you access any data from SQL? I've had a simmilar(but not same) problem when trying to access a SQL connection that has closed during page load. Quite by accident thou, the SQL server has shutdown just as my page has loaded..

 
Old October 13th, 2003, 03:19 AM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got the same problem when I tried to access the web service from .NET (C#) client which was behind a http proxy server.If I access the same web service without using HTTP Proxy ,the calls are successful.There is a remedy for this problem .Just override the method getWebRequest in your reference.cs file .
and add this code
protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

            webRequest.KeepAlive = true;

            return webRequest;
        }
This can solve the problem

 
Old October 30th, 2003, 11:23 AM
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My old post had an error please consider this,
and add this code to reference.cs
protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

            webRequest.KeepAlive = false;
            webRequest.ProtocolVersion=HttpVersion.Version10;
            return webRequest;
        }
This can solve the problem


 
Old October 31st, 2003, 02:28 PM
Registered User
 
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi all,

I have developed a WebApplication that sends messages to mobile phones by connecting to an integrator platform. I use VB.NET. Although my application seems to connect and authorise ok, right after it sends the message, the connection is broken and I get the System.Net.WebException. The first time I run the app, I get an error on a send, all the subsequent runs fail on the receive, the stack trace is the same, though:

[WebException: The underlying connection was closed: An unexpected error occurred on a receive.]
   System.Web.Services.Protocols.WebClientProtocol.Ge tWebResponse(WebRequest request) +58
   System.Web.Services.Protocols.HttpWebClientProtoco l.GetWebResponse(WebRequest request) +5
   System.Web.Services.Protocols.SoapHttpClientProtoc ol.Invoke(String methodName, Object[] parameters) +183
   WebApplication1.localhost.BrokerService.sendsimple message(simplemessageRequest Request, String& ErrorMessage, Object[]& Failed_MSISDN, Int32& RequestID) in C:\Inetpub\wwwroot\WebApplication1\Web References\localhost\Reference.vb:81
   WebApplication1.WebForm1.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:61
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277

I tried the suggested solution, but I still get the same error. Any ideas?

 
Old January 11th, 2004, 10:38 PM
Registered User
 
Join Date: Jan 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to xins
Default

"The underlying connection was closed: An unexpected error occurred on a receive."

hii,
i have the same problem as you. please see this page first for the main problem in .NET web.services :

http://support.microsoft.com/default...en-us%3b819450

well i added thos recommended code but it still has the same error in my program so i add some code and it's works, try this :

private string requestpost(String TheURL,string postdata, String TheProxy)
{
  Uri uri = new Uri(TheURL);
  HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);
  string page;
  try
  {
    string postsourcedata=postdata;

    // start added codes
    request.KeepAlive = false;
    request.ProtocolVersion=HttpVersion.Version10;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = postsourcedata.Length;
    request.Proxy = System.Net.WebProxy.GetDefaultProxy();
    request.AllowAutoRedirect=true;
    request.MaximumAutomaticRedirections=10;
    request.Timeout=(int) new TimeSpan(0,0,60).TotalMilliseconds;
    request.UserAgent="Mozilla/3.0 (compatible; My Browser/1.0)";
    // end added codes

    Stream writeStream = request.GetRequestStream();
    byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postsourcedata );
    writeStream.Write(bytes, 0, bytes.Length);
    writeStream.Close();

    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    Stream responseStream = response.GetResponseStream();
    StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8);

    page = readStream.ReadToEnd();
  }
  catch (Exception ee)
  {
    page = "fail!";
  }
  return page;
}

hopefully your troubled solved..

regards,

-xins.

(by the way have u watch LORD OF THE RING : RETURN OF THE KING?)
:)

See u in matrix
 
Old January 12th, 2004, 01:59 PM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How would I go about writing this in VB.NET. What class would it need to be in and what inheritance would I need.

protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

            webRequest.KeepAlive = false;
            webRequest.ProtocolVersion=HttpVersion.Version10;
            return webRequest;
        }


 
Old May 16th, 2004, 11:51 PM
Registered User
 
Join Date: May 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I campareed two programs reslults-- one is in localhost with aspnet, one is consol program, same programs give different results, why? the firewall can distinguish them?

1st, I use http://localhost/quickstart/howto/sa...ebrequest.aspx
only those pages in local host can be received.
for those pages in internet: back webexception:
System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server.
   at System.Net.HttpWebRequest.CheckFinalStatus()
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncRes ult asyncResult)
   at System.Net.HttpWebRequest.GetResponse()
   at ASP.webrequest_aspx.btnSubmit_Click(Object sender, EventArgs e)

another is almost same program but run in console mode
quickstart/howto/samples/net/WebRequests/clientGET.cs
or
quickstart/howto/samples/net/WebRequests/clientwebexception.cs

I can get right results!

Why? these programs are all .NET 's samples, why give different results?

Who can help me?

if I upload webrequest.aspx to my web site on internet, all OK!

Is it possible for my IIS or proxy server or firewall need some special setting?
------------------

test under VS.NET and C#.net and .NET Frame SDK 1.1, OS is Window 2000 server, IIS 5, and IE 6 as internet explore.


 
Old May 24th, 2004, 08:51 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Must I use webRequest.KeepAlive = false?
I understand what Microsoft writes on theirs page.
But isn't that a simple solution for a complex situation.
Of course I can skip the use of keep alive but what does that do
for my performance?

I found when minimizing the use of static functions and variables makes the error less frequent.
Is there any more redesign one can do to make the error go away??
And keeping the KeepAlive?

/Hansiola




Quote:
quote:Originally posted by misrasandeep
 My old post had an error please consider this,
and add this code to reference.cs
protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

            webRequest.KeepAlive = false;
            webRequest.ProtocolVersion=HttpVersion.Version10;
            return webRequest;
        }
This can solve the problem


 
Old July 28th, 2004, 10:56 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I am also getting the same error, while connecting to SQL reporting service which is a web service by itself.

But if I am updating the reference file, and run the .net program which access the webservice, I get the error "HTTP request aborted. Access denied".

When I delete the reference and add a new one that works.
If anybody has a pointer plz help me.

Thanks
Amit





Similar Threads
Thread Thread Starter Forum Replies Last Post
The underlying connection was closed: An unexpecte ksumijain .NET Web Services 0 April 4th, 2008 12:42 PM
The underlying connection was closed: An unexpecte adabass .NET Framework 1.x 0 October 12th, 2007 08:56 PM
The underlying connection was closed: unable to co badyalsk .NET Web Services 0 January 23rd, 2007 04:42 AM
Underlying connection was closed r_ganesh76 .NET Web Services 0 May 4th, 2006 04:49 AM
The underlying connection was closed: Unable to co anurag_singh02 .NET Web Services 1 August 17th, 2005 11:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.