How to specify proxy/authority for XmlDocument.Load()

15 views
Skip to first unread message

Manfred Braun

unread,
Aug 17, 2003, 12:45:17 PM8/17/03
to
Hi All,

I am trying to access xml-files in the internet from my intranet-page.
Making XmlDocument.Load() calls internally works fine, but not so to the
internet. I think the calls are failing, because we use a proxy-server.

Can I specify a specifix proxy in the call and/or in the
configuration-files? For the configuration-files, I am not finding samples,
which point out how to specify username and password. For the XmlDocument, I
even find nothing in this range, so, do I have to make a webRequest
"manually" specifying a proxy and pass the pulled data to the XmlDocument
after that?

Any help would really be very welcomed!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:_manfred...@manfbraun.de
(Remove the anti-spam-underscore to mail me!)

Oleg Tkachenko

unread,
Aug 17, 2003, 1:41:21 PM8/17/03
to
Manfred Braun wrote:

> I am trying to access xml-files in the internet from my intranet-page.
> Making XmlDocument.Load() calls internally works fine, but not so to the
> internet. I think the calls are failing, because we use a proxy-server.

Read "Supplying Authentication Credentials to XmlResolver when Reading
from a File" at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconsupplyingauthenticationcredentialstoxmlresolverwhenreadingfromfile.asp
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Manfred Braun

unread,
Aug 17, 2003, 4:23:58 PM8/17/03
to
Hi,

and thanks for your posting. After studying this document, I found, that it
does'nt resolve my problem going through a proxy-server. It would apply, to
specify creadentials to the destination. But in my case, the destination-url
is accessibly publicly and I have to deal with our proxy....

Anyway, thanks again and
best regards,
Manfred

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:O2ziJbOZ...@TK2MSFTNGP09.phx.gbl...

Oleg Tkachenko

unread,
Aug 17, 2003, 5:22:20 PM8/17/03
to
Manfred Braun wrote:

> and thanks for your posting. After studying this document, I found, that it
> does'nt resolve my problem going through a proxy-server. It would apply, to
> specify creadentials to the destination. But in my case, the destination-url
> is accessibly publicly and I have to deal with our proxy....

Yeah, you are right, that's not enough.
So you have to deal directly with WebRequest class. There are two ways
I'm aware of - direct one and elegant one. Former - create WebRequest,
set up its proxy property, get WebResponse and load XmlDocument from
response's stream.
More elegant way - encapsulate above WebRequest/WebResponse logic into
custom reusable XmlResolver.

Manfred Braun

unread,
Aug 17, 2003, 6:09:27 PM8/17/03
to
Hi Oleg,

sad to say, this lokks true. Anyway, it's not too much code, but eveythings
is too new for me .....
With help of MSDN/SDK I made the following working successfully:

//+++ excerpt
StreamReader oSR = null;
WebRequest objRequest =
WebRequest.Create("http://msdn.microsoft.com/rss.xml");

bool useProxy =
Boolean.Parse(System.Configuration.ConfigurationSettings.AppSettings["usePro
xy"]);
if(useProxy)
{
string address, port, username, password, domain;
address =
System.Configuration.ConfigurationSettings.AppSettings["address"];
port = System.Configuration.ConfigurationSettings.AppSettings["port"];
username =
System.Configuration.ConfigurationSettings.AppSettings["username"];
password =
System.Configuration.ConfigurationSettings.AppSettings["password"];
domain =
System.Configuration.ConfigurationSettings.AppSettings["domain"];

WebProxy myProxy = new WebProxy(address, Int32.Parse(port));
myProxy.BypassProxyOnLocal = true;
NetworkCredential myCred = new NetworkCredential(username, password,
domain);
myProxy.Credentials = myCred;

objRequest.Proxy = myProxy;
}

WebResponse objResponse = objRequest.GetResponse();
oSR = new StreamReader(objResponse.GetResponseStream());
oDS.ReadXml(oSR);

//--- excerpt

Anyway, thanks for your help. My sample above is from a code, where a
DataSet is used, while I use XmlDocument. But I am shure, I can adapt the
one or two lines of code to use XmlDocument!

Best regards,
Manfred


"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message

news:OxFLoWQZ...@TK2MSFTNGP12.phx.gbl...

Dino Chiesa [MSFT]

unread,
Aug 29, 2003, 12:16:43 PM8/29/03
to
Did you try creating a WebRequest, specifying the proxy there, then creating
a StreamReader() from the response and loading the Xml document from the
StreamReader() ?

what I mean is:
System.Net.WebRequest MyWebRequest = System.Net.WebRequest.Create(URI);
MyWebRequest.Proxy= new WebProxy("server", ProxyPort);
System.Net.WebResponse Response = MyWebRequest.GetResponse();
System.IO.StreamReader Reader = new System.IO.StreamReader
(Response.GetResponseStream());
System.Xml.XmlDocument doc = new System.Xml.XmlDocument ();
doc.Load(Reader);


It feels clunky but I did not see a way to attach a WebProxy to the
XmlDocument.Load() method.

You could also specify the global proxy property, either in a config file or
in code:
System.Net.GlobalProxySelection.Select= new WebProxy("proxyserver", port);

And I believe this setting should be used by the XmlDocument.Load() , as
well as every other outgoing WebRequest.

-Dino


"Manfred Braun" <_manfred...@manfbraun.de> wrote in message
news:ui%23W07NZ...@TK2MSFTNGP12.phx.gbl...

Reply all
Reply to author
Forward
0 new messages