How do you detect when the connection is broken when the web service returns a result?

In a C # ASP.NET application, I have a web service that receives a DataSet, processes it, and returns it.

The return may take up to a minute, slow connection. What happens in the background if this connection is interrupted after the last line of the web service method has started, but while the data is still being sent?

I tried to wrap the web service code in a catch block and disconnect the connection at load time, but no exception was thrown in the web service. I would accidentally find the error:

[WebMethod (Description = "Process data")]
public DataSet Process (DataSet data)
{
   bool success = true;
   StartDatabaseTransaction ();
   DataSet result = Process (data);
   try
   {
      return result; // quickly pull out cable after running this
   }
   catch
   {
      success = false; // never gets here
   }
   finally 
   {
      if (success) CommitTransaction (); else RollBackTransaction ();
   }
   return null;
}
+2


source to share


2 answers


If I read your question and code correctly, you will never hit the catch because of the way web methods work. If you want to catch the timeout error, it must be in the receive method of the dataset. At the point of return, the web server works to transform and transmit data.



+1


source


I'm not sure if this is the right approach, but if it matters, you need to create your own "approval" call from the caller to the server. once the server sends a response, I don't think it is waiting for confirmation.

several ways: using a messaging system (msmq) between the webserver and the webservice, i think with messaging you can achieve this goal as a guaranteed delivery service



Or - force the client to send a pointer with a call and add a web service to it. if the client doesn't get a response in time, have him call the call again with the same director. if the server has already registered this guide, it means the call was a process (and you need to deal with it according to your business logic).

+1


source







All Articles