异步 Web 服务调用的返回值
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有说明您正在使用哪种应用程序,但请查看 如何:使用 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.
在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.