第一次尝试无法从 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。
问题:
我无法 return 直接从 'proxy_wsGetAccountsCompleted' 结果,所以我将该结果存储在全局定义的字符串中,然后在 LoadAccout
的末尾WebMethod return 那个。我可以 return 直接来自 proxy_wsGetAccountsCompleted
.
当我第一次调用 LoadAccount
WebMethod 时,它 return 得到空白结果,如果我第二次调用,我会得到正确的结果。尽管按顺序我在 proxy_wsGetAccountsCompleted
之后 returning 那个全局定义的字符串。是吗?
对 sequence/return 之间的响应感到困惑:
- proxy.wsGetAccountsAsync();
- proxy_wsGetAccountsCompleted();
- return strAccountList
您正在做一些奇怪的事情:调用同步的 wcf 操作,调用异步操作。当然,第一次是行不通的。
LoadAccount() returns 在获取 wsGetAccountsAsync() 结果之前。您可以以同步方式调用 wsGetAccountsAsync 或使用异步操作,例如使用 Signal R。
请记住,当第二次调用该操作时,您将获得先前请求的结果,如果您的方法正在接受某些参数,您将存储一个错误的值,即您先前请求的响应。
[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。
问题:
我无法 return 直接从 'proxy_wsGetAccountsCompleted' 结果,所以我将该结果存储在全局定义的字符串中,然后在
LoadAccout
的末尾WebMethod return 那个。我可以 return 直接来自proxy_wsGetAccountsCompleted
.当我第一次调用
LoadAccount
WebMethod 时,它 return 得到空白结果,如果我第二次调用,我会得到正确的结果。尽管按顺序我在proxy_wsGetAccountsCompleted
之后 returning 那个全局定义的字符串。是吗?
对 sequence/return 之间的响应感到困惑:
- proxy.wsGetAccountsAsync();
- proxy_wsGetAccountsCompleted();
- return strAccountList
您正在做一些奇怪的事情:调用同步的 wcf 操作,调用异步操作。当然,第一次是行不通的。
LoadAccount() returns 在获取 wsGetAccountsAsync() 结果之前。您可以以同步方式调用 wsGetAccountsAsync 或使用异步操作,例如使用 Signal R。
请记住,当第二次调用该操作时,您将获得先前请求的结果,如果您的方法正在接受某些参数,您将存储一个错误的值,即您先前请求的响应。