简体   繁体   中英

Xdocument.load error Unable to connect to remote server

I have an issue with the following

  Dim strPath = String.Concat("http://www.intraneturl.com/xml")
  Dim EmpXDoc As New XDocument
  EmpXDoc = XDocument.Load(strPath)

above code is working good in the development server(connected to intranet) but after hosting the same to production server(connected to both intranet with proxy and internet with public ip) the above code gives "Unable to connect to remote server" error. But if i try to parse the xml website through client javascript as follows :

var parser = new ActiveXObject("microsoft.xmldom");
parser.load("http://www.intraneturl.com/xml");
nodes = parser.documentElement.childNodes;

it works flawlessly.

Which means that the parser is working in client javascript but not in aspx pages (after host). Will some one guide me ?

Well, in one case the parsing takes place on the client (JavaScript), which may not have an internet connection, so it can successfully resolve the intranet url.

The other code runs on the server , which - being connected both internally and externally - may think the intranet url is an extranet url and thus may not be able to resolve it.

You could try to use an IP-Address in your URL to prevent a DNS request.

if you have proxy, set the proxy when you load the document

WebProxy wp = new WebProxy(ProxyAddress);
wp.Credentials = new NetworkCredential(ProxyUsername, ProxyPassword);
WebClient wc = new WebClient(){ Proxy =wp};
MemoryStream ms = new MemoryStream(wc.DownloadData("http://www.intraneturl.com/xml"));
XmlTextReader rdr = new XmlTextReader(ms);
EmpXDoc = XDocument.Load(rdr);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM