Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old October 26th, 2004, 08:52 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #12 (permalink)  
Old March 9th, 2005, 04:15 AM
Registered User
 
Join Date: Mar 2005
Location: , , Iceland.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #13 (permalink)  
Old June 24th, 2005, 12:06 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #14 (permalink)  
Old August 17th, 2005, 11:19 PM
Registered User
 
Join Date: Aug 2005
Location: New Delhi, Delhi, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Dinesh Singh Bisht Send a message via Yahoo to Dinesh Singh Bisht
Default

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


DSBisht
Reply With Quote
  #15 (permalink)  
Old October 12th, 2005, 09:19 AM
Registered User
 
Join Date: Oct 2005
Location: , , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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....
Reply With Quote
  #16 (permalink)  
Old October 12th, 2005, 11:46 AM
Registered User
 
Join Date: Oct 2005
Location: , , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #17 (permalink)  
Old November 1st, 2005, 12:26 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #18 (permalink)  
Old November 20th, 2005, 12:09 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #19 (permalink)  
Old December 16th, 2005, 09:42 AM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #20 (permalink)  
Old December 30th, 2005, 06:59 AM
Registered User
 
Join Date: Dec 2005
Location: Ikaalinen, , Finland.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:12 AM.


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