0

I am trying to understand why a simple call to a feed works only when I have fiddler open.

I've looked at the below links, but none of the answers seem to apply:

HttpWebRequest doesn't work except when fiddler is running

HttpWebRequest only works while fiddler is running

http://blogs.telerik.com/fiddler/posts/13-02-28/help!-running-fiddler-fixes-my-app-

My code is very simple, and as far as I can see, it should just fill the variable with the contents of the xml file:

using (var client = new WebClient())
{                    
    text = client.DownloadString(path);
}

Note that this works perfectly if I am running fiddler, but fails with a timeout error (?) if I run it while fiddler is not running.

I can access the path to the xml file directly from my broswer - so permissions/access does not appear to be a problem either.

http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml

The RAW output from Fiddler is:

HTTP/1.1 200 OK
Via: 1.1 varnish, 1.1 ZTMG01
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Transfer-Encoding: chunked
Age: 19
Date: Mon, 22 Dec 2014 15:23:47 GMT
Content-Type: text/xml
ETag: "dce1c05f259961aeac88cebcdfdbeebe"
Server: AmazonS3
x-amz-id-2: C6oNmRATZO4E7eNiyPhyCOhqT45Mb9Wp0XXaU8KsBQf84gYeNzM9OPAOa9YBNFsL4DGsPSEs5Cw=
x-amz-request-id: 0CE21B93AC8DDC15
Last-Modified: Mon, 22 Dec 2014 15:22:31 GMT
X-TTL-RULE: 8
X-Cacheable: Yes. Cacheable
X-TTL: 60.000
X-Backend: proxy
X-Varnish: 10.76.2.236
X-Backend-Url: http://s3-eu-west-1.amazonaws.com/tfl.pub/Serco/livecyclehireupdates.xml
X-Hash-Url: /tfl.pub/Serco/livecyclehireupdates.xml
Access-Control-Allow-Origin: *
X-Varnish: 181999945 181994842
X-Banning: 
X-Cache: HIT
X-Cache-Hits: 4

Does anyone have any idea why this might be?

Community
  • 1
  • 1
KerSplosh
  • 466
  • 8
  • 26
  • Could this be a proxying issue? WebClient might be 'accidentally' consuming Fiddler's proxy settings, preventing it from running. Can you post the Fiddler RAW output for the successful calls? – pixelbadger Dec 22 '14 at 15:13
  • Updated my question with the RAW output. Nothing untoward as far as I can see here – KerSplosh Dec 22 '14 at 15:29

2 Answers2

5

I can't see how this could be anything other than a proxy configuration issue on the development machine. I've tested the supplied code and URL using LINQPad, and retrieved the XML successfully, both with Fiddler running and not running.

You can override the default proxy configuration of a WebClient instance by setting the Proxy property to null:

string path = "http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml";

using (System.Net.WebClient client = new System.Net.WebClient())
{
    client.Proxy = null;
    client.DownloadString(path);
}

Note that setting Proxy to null will always bypass Fiddler.

pixelbadger
  • 1,556
  • 9
  • 24
  • This makes sense to me, but its still not working (although with the added line setting the proxy to null), fiddler does not work either). I'll try from home tonight to see if this makes a difference. – KerSplosh Dec 22 '14 at 15:55
  • Do you connect to the Internet via a proxy at your office? – pixelbadger Dec 22 '14 at 15:57
  • Just checked - and yes we do – KerSplosh Dec 22 '14 at 16:02
  • Try replacing `client.Proxy = null;` with `client.Proxy = WebRequest.DefaultProxy;` – pixelbadger Dec 22 '14 at 16:08
  • `client.Proxy = WebRequest.DefaultWebProxy;` worked for me, maybe a later version of System.Net? Anyway, very many thanks for your persistance. – KerSplosh Dec 22 '14 at 16:14
  • One last thing - you might want to consider [configuring the proxy to use the default in the web./app.config file](http://msdn.microsoft.com/en-us/library/sa91de1e%28v=vs.110%29.aspx), rather than having to remember to assign it every time you spin up a WebClient/WebRequest instance – pixelbadger Dec 22 '14 at 16:21
1

as magos mentioned this could be a Proxy issue

taken from http://msdn.microsoft.com/en-us/library/system.net.webclient.proxy(v=vs.110).aspx

The Proxy property identifies the IWebProxy instance that communicates with remote servers on behalf of this WebClient object. The proxy is set by the system using configuration files and the Internet Explorer Local Area Network settings. To specify that no proxy should be used, set the Proxy property to the proxy instance returned by the GetEmptyWebProxy method.

try resetting your proxy configuration in your Internet Options of IE

Lior Raz
  • 144
  • 4