【发布时间】:2016-05-03 14:04:31
【问题描述】:
[WebMethod]
public static string LoadAccount()
{
address = new EndpointAddress(objClientSession.ServiceURL);
proxy = new PMToolServices.MyAppServiceClient(binding, address);
//Now call the web service to get the accounts
proxy.wsGetAccountsCompleted += new EventHandler<MyAppServices.wsGetAccountsCompletedEventArgs>(proxy_wsGetAccountsCompleted);
proxy.wsGetAccountsAsync();
return strAccountList;
}
我正在使用ajax 调用LoadAccount WebMethod。在LoadAccount 中,我已将回调proxy_wsGetAccountsCompleted 添加到WCF 的wsGetAccounts。在proxy_wsGetAccountsCompleted 中,我正在构建返回到LoadAccount 的结果。
问题:
我无法直接从“proxy_wsGetAccountsCompleted”返回结果,因此我将该结果存储在全局定义的字符串中,然后在
LoadAccoutWebMethod 的末尾返回该结果。我可以直接从proxy_wsGetAccountsCompleted退回吗?当我第一次调用
LoadAccountWebMethod 时它返回空白结果,如果我再次调用第二次我得到正确的结果。尽管作为序列,我在其上方的proxy_wsGetAccountsCompleted之后返回了该全局定义的字符串。对吗?
对以下之间的序列/返回响应感到困惑:
- proxy.wsGetAccountsAsync();
- proxy_wsGetAccountsCompleted();
- 返回 strAccountList
【问题讨论】: