web services - C# - Unable to Obtain WebException Response from Inner Exception -


i'm catching exception, i've done in 2 ways. first method, i'm catching full exception, checking see if inner exception of type webexception, , if is, obtain response stream. below first example, zero-string response:

catch (exception e) {     if (e.innerexception webexception)     {         webexception webex = (webexception)e.innerexception;         httpwebresponse myresponse = webex.response httpwebresponse;         string response = string.empty;          if (myresponse != null)         {             streamreader strm = new streamreader(myresponse.getresponsestream(), encoding.utf8);             response = strm.readtoend();             //empty response         }     } } 

however, if catch web exception, , pretty same thing, obtain response fine:

catch (webexception e) {     httpwebresponse myresponse = e.response httpwebresponse;     string response = string.empty;      if (myresponse != null)     {         streamreader strm = new streamreader(myresponse.getresponsestream(), encoding.utf8);         response = strm.readtoend();         //populated response     } } 

any ideas why i'm able parse response in second example not in first?

don't @ innerexception, in second example you're reading response exception caught, that's why works. change this, should work fine:

catch (exception e) {   if (e webexception)   {       webexception webex = (webexception)e;       httpwebresponse myresponse = webex.response httpwebresponse;       string response = string.empty;        if (myresponse != null)       {           streamreader strm = new streamreader(myresponse.getresponsestream(), encoding.utf8);           response = strm.readtoend();       }   } } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -