title: Cancel WCF operation on client abort
body: <p>I have a silverlight client that can call a method on my WCF web service to get values from a database. In the case of long query, I want to give the user the option to cancel it.</p>
  
  <p>Client side, when the user press "Cancel", I call ".Abort()" on my WCF instance. However, my WCF service will still continue its operation as it do not know that the client is no longer connected.</p>
  
  <p>My question is: is it possible for a WCF service to know that the client has killed the connection?</p>
  
  <p>I have tried suscribing to the Channel.Closed/faulted events in my contract method, but they never fire...</p>
  
  <pre><code>[AspNetCompatibilityRequirements(RequirementsMode =  AspNetCompatibilityRequirementsMode.Allowed)]
  internal class MyContract: IMyContract
  {
      public object QueryDatabase(...)
      {
          System.ServiceModel.OperationContext.Current.Channel.Faulted += new System.EventHandler(Channel_Faulted);
          System.ServiceModel.OperationContext.Current.Channel.Closed += new System.EventHandler(Channel_Faulted);
  
          // Perform sql query
      }
  
      void Channel_Faulted(object sender, System.EventArgs e)
      {
          // Cancel SQL query here
      }
  }
  </code></pre>
  
  <p>Anyone know how to do this?
  Thanks!</p>