WCF timeouts when invoking an operation in a loop

I wrapped my wcf client in an IDisposable shell and everything works correctly, I have a test case that runs this x times after about 10 times. I'm starting to get a timeout

There is a helper in the calling code wrapped in a using statement, so tbh I lost a little

Does anyone shed light on this?

public class CrmServiceHelper : IDisposable
{
    private CrmServices.CRMServicesClient client;

    public CrmServices.CRMServicesClient GetClient
    {
        get
        {
            lock (this)
            {
                if (client == null)
                    client = new CrmServices.CRMServicesClient();
            }
            return client;
        }
    }
    public void Dispose()
    {
        try
        {
            client.Close();
        }
        catch (CommunicationException ex)
        {
            client.Abort();
        }
        catch (TimeoutException ex)
        {
            client.Abort();
        }
    }
}

Example usage code:

    using (CrmServiceHelper client = new CrmServiceHelper())
    {
        AListReponse resp = client.GetClient.GetAList(companyId);
        if ((resp != null) && (resp.AList != null))
        {
            return resp.AList ;
        }
        else
        {
            return null;
        }
    }

Service Configuration

                                                                                                                                          

+3
source share
3 answers

About 10 times .... it almost sounds like you are pushing a restriction on server throttling ... maybe you are not closing your client proxy? Are client sessions hanging around and the service is not accepting any new incoming requests?

? IIS? ? ?

( , ). .

UPDATE:
" ", wsHttpBinding, . 10 .

:

1) , 10 :

   <behaviors>
      <serviceBehaviors>
        <behavior name="Throttled">
          <serviceThrottling 
            maxConcurrentCalls="25" 
            maxConcurrentSessions="25" 
            maxConcurrentInstances="25" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

, - ...

2) " ", :

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
class YourService : IYourService
{
 ......
}

- 16 - ( MaxInstances ).

+2

( null, , ).

, , ?

0
        for (int j = 0; j < 100; j++)
        {
            using (var client = new ServiceClient())
            {
                client.Method();
            }
         }

- . 1 , 60 1 . ,

0

Source: https://habr.com/ru/post/1712073/


All Articles