Dispose()
will be launched. The only question is: "When?"
The answer to this question depends on the configuration of the service.
There are several possible scenarios:
- Session is not supported by binding
- Regular session
- Reliable session.
Dispose()
started when the session is closed for the context mode of PerSession
. Therefore, we need to check how many sessions work in different scenarios.
For some configurations (for example, default BasicHttpBinding
), the session does not start at all. In the case of a configuration without PerCall
and PerSession
context modes do not differ, and the Dispose
method will be called very soon after the main method is executed.
When the Session
parameter is enabled, it can be explicitly closed by the client or timeout. It is usually controlled by the client. The client initiates the session before the first service call and closes it when the client object is closed.
ServiceClient proxy = new ServiceClient(); Console.WriteLine(proxy.GetData(123)); proxy.Close();
proxy.Close()
method above closes the session on the server, which in turn performs Dispose()
.
Session management is a big driver of performance because it requires additional calls between the client and server to complete it.
Thus, usually Dispose
is called when the client wants to close the session.
If the client did not close the session for any reason, it will be closed by the service host after a certain period of time. This period is controlled by Binding.ReceiveTimeout . The default value for this property is 10 minutes.
The session will be closed and ( Dispose()
started) if no one has sent a request to the server with a specific session identifier within 10 minutes. This default timeout can be changed by setting receiveTimeout
to a slightly shorter value in web.config.
<wsHttpBinding> <binding name="wsHttpEndpointBinding" receiveTimeout="00:00:05"> </binding> </wsHttpBinding>
ReliableSession.InactivityTimeout is additionally checked when a trusted session is enabled. It also defaults to 10 minutes.
It works as expected in IIS self-service and self-service.
Try updating the client code as follows:
using (EightBallClient ball = new EightBallClient()) { ball.ObtainAnswerToQuestion("test"); ball.Close(); }