2
我使用ServiceStack为Web服务API进行原型设计,并在测试GetAsync时遇到了问题。具体来说,当我期望它时,onSuccess动作不会被调用。ServiceStack GetAsync OnSuccess未解雇
这里是我的代码:
服务器:
[Route("/accounts/", "GET")
public class AccountRequest : IReturn<AccountResponse>
{
public string EmailAddress {get; set;}
}
public class AccountResponse
{
public Account Account {get; set;}
}
public class AccountService : Service
{
public object Get(AccountRequest request)
{
return new AccountResponse{Account = new Account.....
}
}
非常基本的,几乎为每个hello上ServiceStack.net
世界的例子和有问题的客户端GetAsync电话:
using(var client = new JsonServiceClient("some url")
{
client.GetAsync(new AccountRequest{EmailAddress = "gibbons"},
response => Console.WriteLine(response.Account.Something), //This never happens
(response, ex) => {throw ex;}); // if it matters, neither does this
}
但是,这与预期完全一样...
using(var client = new JsonServiceClient("some url")
{
var acc = client.Get(new AccountRequest{EmailAddress = "gibbons"});
//acc is exactly as expected.
}
有趣的是,测试异步与非异步一个其他作品太后:
using(var client = new JsonServiceClient("some url")
{
client.GetAsync(new AccountRequest{EmailAddress = "gibbons"},
response => Console.WriteLine(response.Account.Something), //Works
(response, ex) => {throw ex;});
var acc = client.Get(new AccountRequest{EmailAddress = "gibbons"});
//Again, acc is exactly as expected.
}
在所有情况下,我可以看到实际的数据经由小提琴手调过来的HTTP,所以我觉得我错过了一些关于异步api如何工作的基本理解。
任何帮助最受欢迎。谢谢。
是的 - 我只是没有等待足够长的回应。谢谢。 –