Searching for the Response Header property in MessageSecurityException?

I had a requirement in my code wherein I had to make a webservice call, catch a HTTP 401 exception returned by the service, read a value from the header, add some value in the header and call the service again. Seems not very uncommon to me. My client was a WCF application and service was written in Java. Apparently, the exception that was being thrown on client side was of type System.ServiceModel.Security.MessageSecurityException. I remember I tried for about half an hour to find where the hell is the Response object returned from the server. Here it is,

try
{
Webservice Call..
}
catch (MessageSecurityException ex)
{
if (ex.InnerException != null && ex.InnerException is WebException)
{
WebException webException = ex.InnerException as WebException;
string sample = webException.Response.Headers["Sample"];
}
}


Happy Programming!

Abhang Rane


2 comments :

Reader's Comments

  1. If you are interested to buy affordable property in delhi than you should buy through Space India Developer.

    ReplyDelete
  2. Well information provided about, Supertech Limited to launches Supertech Azalia in near future. Thanks for given this information here about this blog.
    Flats in Adambakkam

    ReplyDelete