Reputation: 3215
I am currently calling a webservice from an ASP.net page. I am trying to call a REST based web service to request a certain action and a 404 is returned (which represents a specific error for my application). I try to catch the error but as a 404 is returned my application instead continues to hang and I end up catching the following error.
[System.Net.WebException] = {"The underlying connection was closed: An unexpected error occurred on a receive."}
Why would I catch a different error over 2 seconds after the web service responds with a 404?
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();
}
and that calls this:
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);
Please ignore the [hidden] tags. Ive had to hide that from public view. However, I hope that helps.
Thank you all for your help!
Upvotes: 0
Views: 6033
Reputation: 55946
Since you've provided little information about your system:
You are probably terminating your web service call early with something like
HttpContext.Current.Response.End()
The webservice code (in .NET) is probably trying to complete the request but you've closed the connection early. This happens with Response.Redirect()
too but you never see it on the web-side because you've already completed the output to the user. It's not related to your 404. The web-service code throws the WebException
but there's nothing to handle / format the output.
Update
Based on your feedback I can only deduce that your problem is probably either:
You should download Fiddler2 and sniff the http request to your webservice to verify what's actually going across the wire. If everything checks out then there's only 2 things I can think of:
Request
/Response
is not right. You could use a WebClient
Instead and call either UploadData(...)
or UploadString(...)
to transmit your data to the webservice.WebException: The underlying connection was closed: An unexpected error occurred on a receive. Should only happen when the client expects to recieve data (like a body after a header) but the server terminates the response early.
Upvotes: 2