I have an application written in C# using .Net CF 2.0 which consumes a web service which sits on one of my servers. My device is running WM5 and the dev env is Visual Studio 2005.
In the code, I create the web service, check there's a valid internet connection like this:
req = ((HttpWebRequest)(WebRequest.Create("")));
res = ((HttpWebResponse)(req.GetResponse()));
if(res.StatusCode == HttpStatusCode.OK)
return true;
and then invoke a method on the webservice.

This all works fine with the device cradled until I change my network settings to go via a proxy server.
The PPC seems to pick up these proxy settings after a reset and I can see the web service via IE on the device. However, when I run the code it fails as soon as I try to invoke a method on the web service. The calls to the WebRequest used to check the internet connection still succeeds, but the webservice calls fail.
The exception's HResult is -2146233079 and the _message is "WebException", there is no innerexception.

I've tried setting the following just before I create the webservice:

System.Net.GlobalProxySelection.Select = new System.Net.WebProxy("http://192.168.x.x:6588");

and I also set the following when I create the webservice:

cws.Proxy = new System.Net.WebProxy("http://192.168.x.x:6588");

both of which are using the correct IP and port number.
but this has no effect.

I'm assuming that if the internet connection is fine in the app then I shouldn't need to make these calls anyway. I also assume that I'd only need to set the System.Net.GlobalProxySelection.Select and all subsequence web requests would then use these setting so there'd be no need to specify the proxy when I create the web service.

Does anyone know what the problem is

Re: .NET Compact Framework Web service via a proxy server


OK, I've found what's causing the error, still don't know why though.

When I make a HttpWebRequest and HttpWebResponse I have a finally block which calls Abort() on the request and Close() on the response (if they're not null). This causes my future http requests to fail. This only fails on the CF through a proxy server and not a similar app using the full framework on my laptop or with a direct internet connection.

Is this a bug in the CF Calling either the Abort() or Close() methods on their own causes calls to my web service to fail.

Re: .NET Compact Framework Web service via a proxy server

Andy Rivas - MSFT

I've not been able to reproduce this issue. Could you be trying to call GetResponse() on an closed or aborted response.