Timeout using ServiceStack.Client

你。 提交于 2019-12-01 00:04:30

The issue is due to your ServiceClient requests not specifying a known response type.

Response types can either be marked on the Request DTO using the IReturn<T> marker (recommended):

public class GetAllAdminUsernamesRequest : IReturn<List<string>> { ... }

By adding this on the Request DTO, the ServiceClient is able to automatically infer and convert the response, e.g:

List<string> response = client.Get(new GetCurrentAdminUserAdminTasks());

Otherwise an alternative to specifying the Response on the Request DTO, is to specify it on the call-site, e.g:

List<string> response = client.Get<List<string>>(new GetCurrentAdminUserAdminTasks());

If you don't do this the Response is unknown so the ServiceClient will just return the underlying HttpWebResponse so you can inspect the response yourself.

HttpWebResponse tasks = client.Get(new GetCurrentAdminUserAdminTasks());

In order to be able to inspect and read from the HttpWebResponse the response cannot be disposed by the ServiceClient, so it's up to the call-site making the request to properly dispose of it, i.e:

using (HttpWebResponse tasks = client.Get(new GetCurrentAdminUserAdminTasks())) {}
using (HttpWebResponse adminUsers = client.Get(new GetAllAdminUsernames())) {}

try
{
    using (client.Put(new AssignTask { AdminTaskId = taskId, Assignee = user })) {}
    using (client.Put(new AssignTask { AdminTaskId = taskId, Assignee = user })) {}
    using (client.Put(new AssignTask { AdminTaskId = taskId, Assignee = user })) {}
    using (client.Put(new AssignTask { AdminTaskId = taskId, Assignee = user })) {}
}
...

Disposing of your WebResponses responses will resolve your issue.

If you don't do this the underlying WebRequest will throttle open connections and only let a limited number of simultaneous connections through at any one time, possibly as a safe-guard to prevent DDOS attacks. This is what keeps the underlying connections open and WebRequest to block, waiting for them to be released.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!