Cancel WCF operation upon client interruption

I have a silverlight client that can call a method in my WCF web service to retrieve values ​​from a database. In the case of a long request, I want to give the user the opportunity to cancel it.

Client side, when the user clicks “Cancel”, I call “.Abort ()” in my WCF instance. However, my WCF service will continue to work, as it does not know that the client is no longer connected.

My question is: is it possible for the WCF service to find out that the client has killed the connection?

I tried to judge the ban on the channel. Closed / error events in my contract method, but they never fire ...

[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
    }
}

Does anyone know how to do this? Thank!

+3
source share
2 answers

Faulted Closed , , , , , , . , , , .

<bindings>
  <netTcpBinding>
    <binding>
      <reliableSession ordered="true"
            inactivityTimeout="0:10:0"
            enabled="true" />
    </binding>
  </netTcpBinding>
</bindings>

, , . , .

+2

, , -

  • -.
  • ( async API-
0

All Articles