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)

SQLMaster January 3rd, 2007 11:22 PM

Hi,

I just wanted to add the info that xins' suggestion was the one that helped me out in my VS2005 environment!

From the suggestion I've added:

        req.ProtocolVersion = HttpVersion.Version10
        req.ContentType = "application/x-www-form-urlencoded"
        req.Proxy = System.Net.WebProxy.GetDefaultProxy()
        req.AllowAutoRedirect = True
        req.MaximumAutomaticRedirections = 10
        req.UserAgent = "Mozilla/3.0 (compatible; My Browser/1.0)"

... and now everything is working fine.

Thanks a lot for this suggestion!

The internet gives and the internet takes!

Yours,
Raisor

s8sopr4 January 4th, 2007 05:08 AM

Hi, I have the exception:System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server.

The code is:
Dim URL As String = sRemoteServer
Dim request As HttpWebRequest = WebRequest.Create(URL)
request.Method = "POST"
Dim writer As New System.IO.StreamWriter(request.GetRequestStream())
writer.Write(sParameters)
writer.Close()

Dim response As HttpWebResponse = request.GetResponse()
Dim reader As New System.IO.StreamReader(response.GetResponseStream( ))
Dim str As String = reader.ReadLine()


Could anyone help me, please?
Thanks in advance.


s8sopr4 January 4th, 2007 05:13 AM

I'd like to specify I made a web application, not a web service.


SQLMaster January 4th, 2007 06:19 AM

Hi,

I'm using this in a class and it returns the response string:


    Protected Const ORDERENVIRONMENT As String = "http://www.anyserver.com/order.aspx?ID="

    Protected Function ProcessOrder(ByVal theID as Long, ByVal p1 as String, ByVal p2 as String) As String
        Dim reqStrg As String = String.Empty
        Dim req As System.Net.HttpWebRequest
        Dim res As System.Net.HttpWebResponse
        Dim sr As System.IO.StreamReader
        Dim s As System.IO.Stream
        Dim b As Byte()
        Dim myResult As String = String.Empty
        req = System.Net.WebRequest.Create(ORDERENVIRONMENT + theID.ToString())
        reqStrg = "param1=" + Server.UrlEncode(p1) + "&"
        reqStrg += "param2=" + Server.UrlEncode(p2)
        b = System.Text.Encoding.ASCII.GetBytes(reqStrg)
        req.Method = "post"
        req.ContentType = "application/x-www-form-urlencoded"
        req.KeepAlive = False
        req.Timeout = 30000
        req.ProtocolVersion = HttpVersion.Version10
        req.ContentType = "application/x-www-form-urlencoded"
        req.Proxy = System.Net.WebProxy.GetDefaultProxy()
        req.AllowAutoRedirect = True
        req.MaximumAutomaticRedirections = 10
        req.UserAgent = "Mozilla/3.0 (compatible; My Browser/1.0)"
        req.ContentLength = b.Length
        s = req.GetRequestStream()
        s.Write(b, 0, b.Length)
        res = req.GetResponse()
        sr = New System.IO.StreamReader(res.GetResponseStream())
        myResult = sr.ReadToEnd
        sr.Close()
        res.Close()
        Return myResult
    End Function

Hope this is what you're looking for.

The internet gives and the internet takes!

Yours,
Raisor

nilang19 March 1st, 2007 09:00 AM

following link may be useful

http://nilangshah.wordpress.com/2007...remote-server/

Dheeraj_ahuja March 20th, 2007 11:50 AM

two things to check...
first is check if you are making ur web-service which is behind SSL.
it can be checked by opening inetmgr and go to properties for ur web site and check for directory security tab. here u wll find secure communications and an edit button. jst click on edit and make the setting "require ssl" to uncheckd and the try.
second : jst check your code in the web-service proxy which is being used by ur asp.net application. if "http" is thr then make it https if u want secure communcations

its jst an exp. m sharing here thr might be some other causes too.. :-)



tababar June 18th, 2007 12:44 PM

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

I am still having the same error. i have tried all the code samples mentioned above but did not find any solution. I am accessing the outlook address book (exchange server) from my asp.net/C# code but getting the error on the following function

using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
       return response.Cookies;


F1 F1 plz

olupenko September 20th, 2007 06:52 AM

Hi,

I still have this problem, when i tried many of the codes here the error changed to "remote server failed: 404 file not found"

I am trying to call a perl script from my .NET 1.1 code, this worked fine before firewall were turned on, but then I started getting these errors when the firewall was turned on on my IIS 6.0 server

Can anyone help?

Quote:

quote:Originally posted by tababar
 The underlying connection was closed: An unexpected error occurred on a receive.

I am still having the same error. i have tried all the code samples mentioned above but did not find any solution. I am accessing the outlook address book (exchange server) from my asp.net/C# code but getting the error on the following function

using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
       return response.Cookies;


F1 F1 plz

olupenko September 20th, 2007 07:03 AM

Hi How can I do this in .Net 1.1 for example .Net 1.1 does not accept this line of code
request.ProtocolVersion=HttpVersion.Version10;

Any ideas?


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

yao__junjie December 24th, 2008 04:56 AM


I met this problem these days.And I found that
if Client's System Time is defferent from Server's System Time,a exception will be thrown.

"The underlying connection was closed: An unexpected error occurred on a receive."
Hope It works for you.


All times are GMT -4. The time now is 07:37 AM.

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