Visual Studio .NET - Connect to Remote Server

Asked By laurie long
29-Mar-06 03:40 PM
I am having problems connecting to any remote server when my web application is published to IIS, I don't have these problems when running the web app from Visual Studio. I am connecting to the remote server using HTTPWebRequest. I wrote a snippet of code to just test getting a screen scape from google. Again, the screen scrape works fine when running to from VS, but not from iiS.

The error I receive is:

[SocketException (0x2726): An invalid argument was supplied]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +1001890
   System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +33
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +431

[WebException: Unable to connect to the remote server]
   System.Net.HttpWebRequest.GetResponse() +1501755
   _Default.Page_Load(Object sender, EventArgs e) +61
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

HERE IS THE CODE:

protected void Page_Load(object sender, EventArgs e)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.google.com");

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

StreamReader sr = new StreamReader(resp.GetResponseStream());
string google = sr.ReadToEnd();
sr.Close();

Response.Write(google + "<br>");

}

Do you have IIS on your local machine  Do you have IIS on your local machine

29-Mar-06 04:01 PM
where you can test it there? Obviously there is nothing wrong with your code.
It has to do with either policy or permissions. For example, some hosted servers are set not to permit WebRequest calls going out from the machine.

Connect to Remote Server  Connect to Remote Server

29-Mar-06 04:08 PM
Yes, I am testing the web app on my local machine's IIS. 

It is setup to use anonymous access. And, I did for kicks, change it to Integrated Windows Authentication, but that did not seem to make a difference. I also tried to have the Anonymous Access use my local account just to see if that made a difference, but it did not. 

I have disabled my Windows Firewall and the Microsoft Windows Client for ISA Server 2004. 

Any idea on any policy or permissions that will allow this simple request to go through?

Unable to connect to server  Unable to connect to server

30-Mar-06 12:25 PM
We finally figured out a resolution to this problem. When we uninstalled MS Firewall Client from any machine hosting the web application this allowed our httpwebrequest to get the info it needed from the internet. 

I only came to this conclusion after finding another post on it....with the error "A socket operation encountered a dead network" instead of the orignal message I got, "An invalid argument was supplied", although once, i did get the dead network exception.

The post also mentioned the tag <defaultProxy> not being in the machine.config of the 2.0 framework, but adding this did not solve this problem.. here is the snippet from the post and the link...

http://www.mcse.ms/archive109-2005-11-1963996.html

It ended up with something to do with our Proxy configuration. On both the
1.1 & 2.0 boxes I had the MS Firewall Client installed. This worked fine on
the 1.1 box, but on the 2.0 box for some reason the httpwebrequest couldnt
get out. I un-installed the firewall client on the 2.0 box and it ended up
working fine? Our proxy server (isa 2004) was configured to allow all
outbound connections for both the boxes. So I dont see where the problem
was?

TIA!

<param@community.nospam> wrote in message
news:OePTDKt5FHA.444@TK2MSFTNGP11.phx.gbl...[vbcol=seagreen]
> Steve,
>
> 1. Yes I can visit that page directly through a browser on the server.
> 2. The same code snippet works on another server on the same network
> running net 1.1.
> 3. The vdir is running with anonymous authentication turned on. It's
> application pool is configured to run under a normal user account named
> "appone".
>
> I cant think of anything else?
>
> "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
> news:q4h%23NPs5FHA.2108@TK2MSFTNGXA02.phx.gbl...
>
>[/vbcol]


Steven Cheng[MSFT]

2005-11-13, 9:12 pm
	Hi Param,

Thanks for your followup.
I think the behavior you mentioned could be caused by the new configuration
of the
<system.net><defaultProxy>.......

in .net 2.0, which will use the IE setting if there is not default proxy
configured...
In .net 1.1, there is default setting in machine.config which point the
default proxy setting is:

<sytem.net>
....
<defaultProxy>
<proxy usesystemdefault="true"/>
...........


while in .NET 2.0, this is not configured by default in the machine.config.
You can check the setting on your deve machine's machine.config. Also,
you can override this setting in your Application's application config file
/web.config file...
Create New Account
help
visual studio.net 2003 and Access 2007 database .NET Framework Hi I am currently using Visual Studio.Net 2003 running on Windows Server 2000 operating system. I have used Visual Studio.net 2003 connecting to Access 2002 databases in the pass with great success. Now
Visual Studio .net .NET Framework Hi NG, ich habe vor längerer Zeit mit Visual Studio .Net 2003 gearbeitet und überlege momentan auf einen neueren Stand upzudaten. Ein Visual Studio .Net 2008 scheint es nicht zu geben. Habe zumindest mit googeln nichts gefunden. Was
Wise for Visual Studio.NET Wise for Visual Studio.NET By Peter A. Bromberg, Ph.D. To "Print This Page" Link Peter Bromberg Wise for Visual Studio .NET is a total and complete installation development system for creating and editing Windows® Installer
Visual Studio versioning . . . . how to tell? .NET Framework To my knowledge, Visual studio 6 was released in 1998, then Visual Studio .NET 2002 is VS 7, then Visual Studio .NET 2003 is VS 7.1, then Visual
Is Visual Studio self-hosting ? .NET Framework Does Microsoft use Visual Studio IDE, Visual Studio Debugger, Visual Studio Linker and Visual Studio compiler for developing Visual Studio ? Or is Visual Studio not