p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   .NET Web Services (http://p2p.wrox.com/forumdisplay.php?f=102)
-   -   The underlying connection was closed: (http://p2p.wrox.com/showthread.php?t=4586)

preis October 26th, 2004 08:52 AM

xins please, could you provide me a sample to how can I use it.
Thank you.:)
Quote:

quote:Originally posted by xins
 "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

hape79 March 9th, 2005 04:15 AM

This is an old thread so someone must have an answer to my question.
I am getting the same error as jhause that started this thread 'The underlying connection was closed: An unexpected error occurred on a RECEIVE'
But every advise to this error is a solution to another problem 'The underlying connection was closed: An unexpected error occurred on a SEND'
So if someone knows how to fix the RECEIVE error please post it here.
Since none of the above seems to correct that error for me.
Thanks


sebastiansony June 24th, 2005 12:06 AM

Can U please tell me how can we send SMS from ASP.NET?, Please... Do we need any 3rd party support..?


Dinesh Singh Bisht August 17th, 2005 11:19 PM

Hi All,
 this "The underlying connection was closed" often comes when you access the something of which you don't have access.


DSBisht

kallax October 12th, 2005 09:19 AM

Hi guys,

I had the same problem as okll and found that the ACLs on the target file were too restrictive. (Thanks for the help, Dinesh!) Unfortunately this has not solved the problem, though. I am still on the trail....

kallax October 12th, 2005 11:46 AM

SOLUTION?

I wrote a utility to test the faulty sites: it is a winforms application, and returns "407: remote proxy requires authentication". I hope this is of help.


amit211278 November 1st, 2005 12:26 AM

Hi all,

I am also getting the same problem "System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive."
I have installed the client certificate on my development maching(Window XP). i m using the following code..

HttpWebResponse result = null;

            //System.Web.UI.Page obj = new System.Web.UI.Page();

            try
            {

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(m_url);
                req.Credentials = CredentialCache.DefaultCredentials;

                ///Method1
                //req.ClientCertificates.Add(X509Certificate.CreateF romCertFile("D:\\Temp\\cert\\c1.cer"));

                ///Method2
                ///Uses interop services
                MyCerts mycert = new MyCerts();
                mycert.CertName = certName;

                if(mycert.Init() > 0)
                {
                    req.ClientCertificates.Add(mycert[0]);
                }

                try
                {
                    result = (HttpWebResponse)req.GetResponse();
                }
                catch (WebException ex)
                {
                    if (ex.Status == WebExceptionStatus.ProtocolError)
                    {
                        HttpWebResponse response = ex.Response as HttpWebResponse;
                        if (response != null)
                        {
                            result = response;// (HttpWebResponse)req.GetResponse();
                        }
                    }

                }

                Stream ReceiveStream = result.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

                StreamReader sr = new StreamReader( ReceiveStream, encode );

                Char[] read = new Char[256];
                int count = sr.Read( read, 0, 256 );
                return mycert[0];
            }
            catch//(WebException e)
            {
                return null;
            }
            finally
            {
                if ( result != null )
                {
                    result.Close();
                }

            }
            return null;



//this function is working fine it returns the certificate from my machine
public int Init()
        {

            Microsoft.Web.Services2.Security.X509.X509Certific ateStore store =
                Microsoft.Web.Services2.Security.X509.X509Certific ateStore.LocalMachineStore(Microsoft.Web.Services2 .Security.X509.X509CertificateStore.MyStore);
            store.OpenRead();
            // Looks for the first certificate called SecureMathClient in the Local
            // machine store
            Microsoft.Web.Services2.Security.X509.X509Certific ateCollection col = (Microsoft.Web.Services2.Security.X509.X509Certifi cateCollection)store.FindCertificateBySubjectStrin g(certName);
            X509Certificate cert = null;
            try
            {
                cert = col[0] ;
                m_certs = col;
                string s = col[0].GetName();
            }
            catch (Exception ex)
            {
                throw new Exception("Certificate not Found!");

            }
            return m_certs.Count;
        }

i m getting the exception at (HttpWebResponse)req.GetResponse();.....
Any idea!!!!!!!!!

Thanks
Amit


redbrad0 November 20th, 2005 12:09 PM

We are having the same problem..

Error Message
The underlying connection was closed: An unexpected error occurred on a receive

Code
byte[] data = System.Text.Encoding.ASCII.GetBytes(strPOST);
WebRequest request = WebRequest.Create(URL);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.ContentLength = data.Length;
request.Timeout = 120000;

The error occurs on the red line. Does anyone have a fix?


JordanGD December 16th, 2005 09:42 AM

Hi all,

I have a problem with code above:
    protected override WebRequest GetWebRequest(Uri uri)
    {
       HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);
       webRequest.KeepAlive = false;
       webRequest.ProtocolVersion=HttpVersion.Version10;
       return webRequest;
    }
When I added the code to Reference.cs and I started the application it throws
System.Net.WebException: The request failed with HTTP status 401: Access Denied.

I'm using Windows Authentication. And the following code to call the web service:
    testService.Service service = new WindowsApplication1.testService.Service();
    service.Credentials = CredentialCache.DefaultCredentials;
    label1.Text = service.HelloWorld();

Anyone else had this problem?


vmattila December 30th, 2005 06:59 AM

I encounter this error when trying to add a web reference. Pointing the wizard to correct URL (that resides in another place at the Internet, not on our intranet nor my local workstation), I get error "The underlying connection was closed" to the right side of the wizard and to the main, "large" window IE's error screen.

When I go to the WSDL address via IE directly, I will see the WSDL file properly. After one visit at WSDL address with IE, the Web Reference wizard is able to show the contents of WSDL in main window, but doesn't show up any services to the right "Methods" window. The underlying connection was closed -error remains up there.

I'm not behind a proxy at all, so it should not be a proxy issue. Trying to close the firewall doesn't help either.

Any ideas?

Thanks,
Ville



All times are GMT -4. The time now is 10:22 PM.

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