异步 Web 服务调用的返回值

发布于 2024-08-01 13:35:06 字数 397 浏览 2 评论 0原文

我在 VS 2005 的 VB.Net 中使用 ASMX Web 服务。我在 Web 服务上调用返回 true 或 false 值的函数方法。 如果我同步调用 web 方法,这样效果很好,但如果我想异步调用该方法,该函数将返回到 sub 并且没有返回值; 因此,我无法判断调用结果是 true 还是 false。 有没有办法进行异步调用并仍然获得 true 或 false 结果(也许使用 userState 对象)?

例如:

Dim MyResult as Boolean = MyService.GetResult(10)
Dim MyResult as Boolean = MyServer.GetResultAsync(10) 

这不起作用,编译器抱怨:“表达式不产生值”

I'm using ASMX web services in VB.Net in VS 2005. I am calling a function method on the web service that returns a true or false value. This works fine if I call the the web method synchronously, but if I want to call the method asynchronously, the function returns to a sub and there is no return value; therefore, I can't tell whether the result of call is true or false. Is there a way to make an asynchronous call and still get the true or false result (perhaps using the userState Object)?

For Example:

Dim MyResult as Boolean = MyService.GetResult(10)
Dim MyResult as Boolean = MyServer.GetResultAsync(10) 

This doesn't work the compiler complains: "Expression Does Not Produce a Value"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丢了幸福的猪 2024-08-08 13:35:06

您没有说明您正在使用哪种应用程序,但请查看 如何:使用 ASP.NET 2.0 实现事件驱动的异步 Web 服务客户端

You don't say what kind of application you're using, but take a look at How to: Implement an Event-Driven Asynchronous Web Service Client Using ASP.NET 2.0.

望笑 2024-08-08 13:35:06

在VS为您创建的代理类中必须存在类似于BeginGetResult的东西 - 该方法返回接口IAsyncResult - 在它们的帮助下您可以检测执行何时完成。 之后你会得到一个值。

In the proxy class that VS creates for you must exists something looking like BeginGetResult - this method returns interface IAsyncResult - with help of them you can detect when execution done. After it you will get a value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文