Click here to Skip to main content
15,911,786 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to prevent remote log off Pin
fjdiewornncalwe21-Dec-11 9:04
professionalfjdiewornncalwe21-Dec-11 9:04 
GeneralRe: How to prevent remote log off Pin
turbosupramk321-Dec-11 9:08
turbosupramk321-Dec-11 9:08 
GeneralRe: How to prevent remote log off Pin
fjdiewornncalwe21-Dec-11 9:48
professionalfjdiewornncalwe21-Dec-11 9:48 
GeneralRe: How to prevent remote log off Pin
turbosupramk321-Dec-11 10:01
turbosupramk321-Dec-11 10:01 
AnswerRe: How to prevent remote log off Pin
Dave Kreskowiak21-Dec-11 10:22
mveDave Kreskowiak21-Dec-11 10:22 
GeneralRe: How to prevent remote log off Pin
turbosupramk321-Dec-11 10:45
turbosupramk321-Dec-11 10:45 
AnswerRe: How to prevent remote log off Pin
jschell22-Dec-11 8:15
jschell22-Dec-11 8:15 
QuestionXML from URL Causes Internal Server Error (500) Pin
Enochs21-Dec-11 5:41
Enochs21-Dec-11 5:41 
I use a web based look-up service to obtain detailed information on IP addresses. It works great until the service goes down and the URL fails to render proper XML.

The error (when the service is down) occurs on the "xDoc = XDocument.Load(url)" statement but does NOT throw an XmlException that I can catch...instead the server (I use a host) locks up with an internal (500) error. Since this error is from the server and not my application, I get no stack trace.

All of my XML validation methods are predicated on the fact that I have the XDocument loaded first....then validate against an XML schema. But it's the load that fails so I have no chance to validate the XML. Any Ideas?

C#
string url = String.Format("http://www.ipgp.net/api/xml/{0}/{1}", sourceIP, password);
try
{   /* This returns an internal server
     * error (500) if the url fails to 
     * render proper xml. No error 
     * gets thrown.  */
     xDoc = XDocument.Load(url);
}
catch (XmlException ex)
{
    /* This is a safe xml document
     * that I would like to load if
     * the load fails.  */
     xDoc = XDocument.Load(safe);
}


UPDATE:
I figured out this UGLY hack to get around the problem for now. The following code first reads the webpage into a variable and then checks the variable for an XML tag that I know should be present. If XML tag can't be found then my default (safe) xml loads. I hope someone can PLEASE give me a better fix...thanks

HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8); 
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();          
            
if (ExactMatch(result, "<Country>"))
   xDoc = XDocument.Load(url);
else
   xDoc = XDocument.Load(Safe);


modified 21-Dec-11 18:13pm.

AnswerRe: XML from URL Causes Internal Server Error (500) Pin
fjdiewornncalwe21-Dec-11 7:10
professionalfjdiewornncalwe21-Dec-11 7:10 
GeneralRe: XML from URL Causes Internal Server Error (500) Pin
Enochs21-Dec-11 9:02
Enochs21-Dec-11 9:02 
GeneralRe: XML from URL Causes Internal Server Error (500) Pin
fjdiewornncalwe21-Dec-11 9:08
professionalfjdiewornncalwe21-Dec-11 9:08 
GeneralRe: XML from URL Causes Internal Server Error (500) Pin
Enochs21-Dec-11 12:07
Enochs21-Dec-11 12:07 
AnswerRe: XML from URL Causes Internal Server Error (500) Pin
jschell22-Dec-11 8:20
jschell22-Dec-11 8:20 
QuestionIssues of Making MS-Access Schema Pin
Rajesh Singh00721-Dec-11 3:19
Rajesh Singh00721-Dec-11 3:19 
AnswerRe: Issues of Making MS-Access Schema Pin
Luc Pattyn21-Dec-11 3:47
sitebuilderLuc Pattyn21-Dec-11 3:47 
GeneralRe: Issues of Making MS-Access Schema Pin
Rajesh Singh00721-Dec-11 4:06
Rajesh Singh00721-Dec-11 4:06 
AnswerRe: Issues of Making MS-Access Schema Pin
Luc Pattyn21-Dec-11 4:21
sitebuilderLuc Pattyn21-Dec-11 4:21 
AnswerRe: Issues of Making MS-Access Schema Pin
riced21-Dec-11 11:31
riced21-Dec-11 11:31 
AnswerRe: Issues of Making MS-Access Schema Pin
SilimSayo22-Dec-11 13:09
SilimSayo22-Dec-11 13:09 
QuestionWrong Target set in Desktop shortcut Pin
iamdking21-Dec-11 0:57
iamdking21-Dec-11 0:57 
AnswerRe: Wrong Target set in Desktop shortcut Pin
Richard MacCutchan21-Dec-11 3:06
mveRichard MacCutchan21-Dec-11 3:06 
GeneralRe: Wrong Target set in Desktop shortcut Pin
iamdking21-Dec-11 19:24
iamdking21-Dec-11 19:24 
GeneralRe: Wrong Target set in Desktop shortcut Pin
Richard MacCutchan21-Dec-11 21:56
mveRichard MacCutchan21-Dec-11 21:56 
GeneralRe: Wrong Target set in Desktop shortcut Pin
iamdking21-Dec-11 23:56
iamdking21-Dec-11 23:56 
GeneralRe: Wrong Target set in Desktop shortcut Pin
Richard MacCutchan22-Dec-11 0:55
mveRichard MacCutchan22-Dec-11 0:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.