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
  #21 (permalink)  
Old January 3rd, 2007, 11:22 PM
Registered User
 
Join Date: Jan 2007
Location: Ingelheim am Rhein, Rheinland-Pfalz, Germany.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #22 (permalink)  
Old January 4th, 2007, 05:08 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #23 (permalink)  
Old January 4th, 2007, 05:13 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #24 (permalink)  
Old January 4th, 2007, 06:19 AM
Registered User
 
Join Date: Jan 2007
Location: Ingelheim am Rhein, Rheinland-Pfalz, Germany.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #25 (permalink)  
Old March 1st, 2007, 09:00 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

following link may be useful

http://nilangshah.wordpress.com/2007...remote-server/
Reply With Quote
  #26 (permalink)  
Old March 20th, 2007, 11:50 AM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.. :-)


Reply With Quote
  #27 (permalink)  
Old June 18th, 2007, 12:44 PM
Registered User
 
Join Date: Jun 2007
Location: Lahore, Punjab, Pakistan.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #28 (permalink)  
Old September 20th, 2007, 06:52 AM
Registered User
 
Join Date: Sep 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #29 (permalink)  
Old September 20th, 2007, 07:03 AM
Registered User
 
Join Date: Sep 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #30 (permalink)  
Old December 24th, 2008, 04:56 AM
Registered User
 
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default


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.
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 01:59 AM.


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