我目前正在从 ASP.net 页面调用 web 服务。我正在尝试调用基于 REST 的 Web 服务来请求某个操作并返回 404(这代表我的应用程序的特定错误)。我尝试捕捉错误,但是当返回 404 时,我的应用程序反而继续挂起,我最终捕捉到以下错误。
[System.Net.WebException] = {“底层连接已关闭:接收时发生意外错误。”}
为什么在 Web 服务响应 404 后 2 秒内我会捕获到不同的错误?
try
{
newPassword = Customer.ResetPassword(_transaction.Centre.Id, newPassword);
}
catch(WebException ex)
{
HttpWebResponse response = (HttpWebResponse)ex.Response;
if ((response != null) && (response.StatusCode == HttpStatusCode.NotFound))
{
//then the email address doesnt exist
ErrorPage(104);
}
else
{
ErrorPage();
}
}
catch (Exception ex)
{
ErrorPage();
}
这就是所谓的:
Request currentRequest = new Request(uri,
Communication.Request.HttpRequestType.POST,[hidden][hidden]);
Response response = currentRequest.Send(Serializer.Serialize<ResetPassword (resetPassword));
return Serializer.Deserialize<ResetPassword>(response.BodyData);
请忽略 [隐藏] 标签。我不得不从公众视野中隐藏它。但是,我希望这会有所帮助。
谢谢大家的帮助!