简体   繁体   中英

ServiceStack 4 C# client async call hangs

I am using ServiceStack 4 client to access a RESTful api endpoint. I have written two methods to return a list of objects. The synchronize method returns data as expected. The async methods hangs on the line :

var response = await client.GetAsync<List<Debtor>>("api/Debtor");

This is how my methods are defined:

    public async Task<List<Debtor>> GetDebtorsAsync()
    {
        var debtors = new List<Debtor>();

        try
        {
            var client = new JsonServiceClient(GlobalSingleton.ServerURI);
            var response = await client.GetAsync<List<Debtor>>("api/Debtor");
            debtors = response;
        }
        catch (Exception ex)
        {
            throw;
        }
        return debtors;
    }

    List<Debtor> IDebtorDal.GetDebtors()
    {
        var debtors = new List<Debtor>();

        try
        {
            var client = new JsonServiceClient(GlobalSingleton.ServerURI);
            var response = client.Get<List<Debtor>>("api/Debtor");
            var r = response.GetResponseStatus();
            debtors = response;
        }
        catch (Exception ex)
        {
            var x = ex.Message;
            throw;
        }
        return debtors;
    }

The ServiceStack Service Clients should only be used for calling ServiceStack Services . You can use HTTP Utils for calling 3rd party (ie non-ServiceStack) services.

The JsonServiceClient uses .NET's HttpWebRequest which has a default limit on the number of concurrent HTTP Requests to a single domain which you can increase with:

ServicePointManager.DefaultConnectionLimit = n;

Alternatively for async requests you can use JsonHttpClient instead which is built on Microsoft's newer HttpClient which doesn't have these limits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM