第一次尝试无法从 WCF 服务的 ajax 函数调用中获取数据

Unable to get data from ajax function call from WCF service in first attempt

[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 中,我将 return 的结果构建到 LoadAccount。 问题:

对 sequence/return 之间的响应感到困惑:

您正在做一些奇怪的事情:调用同步的 wcf 操作,调用异步操作。当然,第一次是行不通的。

LoadAccount() returns 在获取 wsGetAccountsAsync() 结果之前。您可以以同步方式调用 wsGetAccountsAsync 或使用异步操作,例如使用 Signal R。

请记住,当第二次调用该操作时,您将获得先前请求的结果,如果您的方法正在接受某些参数,您将存储一个错误的值,即您先前请求的响应。