Search code examples
c#.netwcfwcf-client

WCF method not invoked


I have a very strange problem. I have a WCF service and a console application that invokes some of it methods. At some point, it can't invoke one of them any more. It just calls the method, but it never enters it. It just waits and waits.. and nothing ever happens.

Should I maybe somehow refresh the service client? I tried creating a new service client object

QueryingServiceClient queryingClient = new QueryingServiceClient();

and then to call the method again, but it didn't work. Just to add that I call that method and several other ones few times before it stops working.

Any ideas?

Thanks.


Solution

  • Assumptions:

    • your service uses the Session instance mode (the default mode)
    • your client creates a new instance of the proxy for every call it makes to the service.
    • your client does not dispose the proxies after the calls.

    The problem is probably that you are depleting the number of available slots (sessions in that case) on the server to the point where you are reaching the maximum number of concurrent sessions. Then your client will wait depending on the defined timeout for a session to be closed on the service side (which obviously will never happen in that case).

    Suggested fixes:

    • Set the InstanceContextMode to PerCall, unless you really need WCF sessions.
    • Always close your proxies after use.

    EDIT:

    using (var proxy = new Proxy())
    {
        // Use the proxy as much as needed
        proxy.Method();
    }