Я немного озадачен, почему мое исключение try ... catch не работает должным образом. Я установил следующий код, который прекрасно работает - для вызова WCF-службы restful. Я решил проверить его, отключив службу WCF restful в надежде, что он перехватит сообщения об ошибках или проигнорирует сообщение 200 (ок) и т. Д., Но по какой-то причине ... try catch и response. ошибка HttpStageProcessingException в середине попытки catch ..
Насколько я понимаю, мне нужно отлавливать ArgumentOutOfRangeException, только когда 200 игнорируется ... мысли?
// set up passing parameters
var p = new HttpQueryString();
p.Add("username", username);
p.Add("password", password);
try
{
WebConfigurations cfg = new WebConfigurations();
HttpResponseMessage response;
// cfg - gets the base address for the URL of the WCF
using (HttpClient client = new HttpClient(cfg.GetBaseUrl()))
{
// exception HttpStageProcessingException occurs here...
response = client.Get(new Uri(client.BaseAddress + "MainService/ValidateUser"), p);
response.EnsureStatusIsSuccessful();
string memberallowed = string.Empty;
// process the resonse xml etc..NOT a problem...
ProcessStreamData proc = new ProcessStreamData();
memberallowed = proc.ReadStreamData(response);
// blah balh
return result;
}
}
catch (ArgumentOutOfRangeException aorEx)
{
Console.Write("Argument Out of Range: " + aorEx.Message);
return false;
}
// This really should not be here??? No error message is generated, too...
catch (HttpStageProcessingException timeEx)
{
Console.Write("Stage Processing" + timeEx.Message);
return false;
}
catch (Exception ex)
{
Console.Write("Standard error" + ex.Message);
return false;
}