tags:

views:

3558

answers:

6

I have a bit of code that basically reads an XML document using the XMLDocument.Load(uri) method which works fine, but doesn't work so well if the call is made through a proxy.

I was wondering if anyone knew of a way to make this call (or achieve the same effect) through a proxy?

+4  A: 

You can't configure XMLDocument to use proxy. You can use WebRequest or WebClient class to load data via proxy and pass obtained response stream to XMLDocument

Also you can try to use XmlTextReader class. It allows you set network credentials. For details see:

Supplying Authentication Credentials to XmlResolver when Reading from a File

aku
+1  A: 

You need to use WebProxy and WebRequest to download the xml, then parse it.

Alexander Kojevnikov
+3  A: 

Do you have to provide credentials to the proxy?

If so, this should help: "Supplying Authentication Credentials to XmlResolver when Reading from a File" http://msdn.microsoft.com/en-us/library/aa720674.aspx

Basically, you...

  1. Create an XmlTextReader using the URL
  2. Set the Credentials property of the reader's XmlResolver
  3. Create an XmlDocument instance and pass the reader to the Load method.
Brandon Payton
+2  A: 

This is the code that I ended up using:

WebProxy wp = new WebProxy(Settings.Default.ProxyAddress);
wp.Credentials = new NetworkCredential(Settings.Default.ProxyUsername, Settings.Default.ProxyPassword);
WebClient wc = new WebClient();
wc.Proxy = wp;

MemoryStream ms = new MemoryStream(wc.DownloadData(url));
XmlTextReader rdr = new XmlTextReader(url);
return XDocument.Load(rdr);
lomaxx
+2  A: 

Use lomaxx's answer but change

MemoryStream ms = new MemoryStream(wc.DownloadData(url));XmlTextReader rdr = new XmlTextReader(url);

to

MemoryStream ms = new MemoryStream(wc.DownloadData(url));XmlTextReader rdr = new XmlTextReader(ms);
A: 

Has anyone tried this with javascript?

More precisely, I have an application that uses javascript (aka AJAX) to load xmldocuments that come from SQL Server "for XML" stored procs. Everything works great for local users, users signed directly to IIS server via tunnel/vpn. But, I have a group of users that come in to one VPN, come through ISA proxy to get to another VPN tunnel to the IIS server.

Somewhere I read that you are not permitted to xmlDocument.load across a proxy. True?

Any body have anything to add? I'm trying to get more specific details of the network topography.