What happens when I close/abort a WCF channel/proxy?

后端 未结 1 514
遇见更好的自我
遇见更好的自我 2021-02-02 10:36

I\'m trying to get a better understanding of what\'s going on when I use a WCF proxy. I\'m having trouble understanding what happens when I close (or don\'t close) a proxy.

相关标签:
1条回答
  • 2021-02-02 11:14

    Closing WCF client
    A client has an inherited responsibility of gracefully closing the connection. It is always recommended to close a proxy client. If the binding between a client and a service is transport-layer sessionful, then closing a proxy is essential to tear down the connection between both parties. Service has a payload threshold defined for concurrent connections. If the number of concurrent connections goes above this threshold linearly then the overall service performance decreases exponentially. This is why it is crucial to dispose of the connection as soon as possible. Closing the proxy also notifies the service instance that it is no longer in use and may be collected by GC (subject to service instance management). If the client does not close a connection, it is still automatically torn down by WCF timeouts (found in the configuration files).

    Aborting WCF client
    In the situation where there is a fault in the service-client interaction, the objects on both ends are potentially totally broken. Thus using a proxy after the exception is not advised. Given the WCF binding use transport sessions, the client after a fault would not even be able to close it (if there was no transport layer session then the client could use or close the proxy, but this is not recommended as the configuration of sessions could change). So after a fault has happened the only safe operation is to abort a proxy.

    Close is a synchronous operation, it can throw if the transport session has been damaged by a fault and it is a blocking operation until a confirmatory response from service is received (true for some bindings).

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