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如何工作的基本理解。
任何幫助最受歡迎。謝謝。
是的 - 我只是沒有等待足夠長的迴應。謝謝。 –