Detecting Client Death in WCF Duplex Contracts

后端 未结 2 1651
星月不相逢
星月不相逢 2020-11-29 19:44

I\'m trying to build a SOA where clients can perform long running queries on the server and the server responds using a callback.

I\'d like to be able to detect if t

相关标签:
2条回答
  • 2020-11-29 20:24

    try this to check if the callback object is still valid:

    (((ICommunicationObject)myCallbackObject).State == CommunicationState.Opened)
    

    myCallbackObject in this case is the object through which you can perform the callback, i.e. the one implementing the callback contract

    0 讨论(0)
  • 2020-11-29 20:34

    In his 'Programming WCF Services' book, Juval Lowy explains that WCF does not provide a mechansim for managing service callbacks, and this must be managed by the service and client explicitly. If the service attempts to invoke a callback which has been closed on the client, an ObjectDisposedException will be thrown on the service channel.

    He recommends adding a Connect and Disconnect method to the service contract - since the callback must be provided to the service when these are called, the service can manage client callbacks. It is then up to the client to ensure that it calls Disconnect when it no longer wishes to recieve callbacks from the service, and the service must handle any exceptions when invoking callbacks to the client.

    0 讨论(0)
提交回复
热议问题