views:

102

answers:

1

I'm calling a method on a webservice and it is throwing a 403 Forbidden WebException...

System.Net.WebException: The request failed with HTTP status 403: Forbidden.

I've got this error logged but I'd really like to have the URI recorded in the log message so it is easy to determine which webservice is causing the problem.

Is there a simple way to get the URI from the WebException that is thrown? I've looked through the list of properties and I can't see anything that will get me what I want.

+1  A: 

You can access the Url property on your SOAP client proxy object (SoapHttpClientProtocol type).

If you're calling two different web services from one method in your code, simply put a try {} catch around the web service calls and throw an appropriate custom Exception with the Url property of the offending web service.

Something like:

string url = client.Url;
try
{
  client.MyWebServiceCall();
  url = client2.Url;
  client2.MyWebServiceCall2();
}
catch (Exception ex)
{
  throw new Exception("Webservice call failed. Url: "+url+", Error:"+ex.Message,ex);
}
Wim Hollebrandse
I'm marking this one as the answer because I didn't realise the webservice had access to a Url property...and since my code had a wrapper around the webservice which didn't replicate the Url I had no access to it. I've change my code to give the Url on the wrapped webservice and made sure my try-catch is only around one service call.
mezoid