下面是我用来在 SilverLight 中使用 Web 服务的代码。
private void button1_Click(object sender, RoutedEventArgs e)
{
BasicHttpBinding bind = new BasicHttpBinding();
EndpointAddress endpoint = new EndpointAddress("http://loalhost/Service.asmx");
ServiceSoapClient client = new ServiceSoapClient(bind, endpoint);
client.RunHelloCompleted += new EventHandler<RunHelloCompletedEventArgs>(client_RunQwinCompleted);
client.RunHelloAsync(command);
}
void client_RunHelloCompleted(object sender, RunHelloCompletedEventArgs e)
{
txtProcess.Text=Process(e.Result);
}
我想知道一种方法,在我运行 RunHelloAsync(Command) 之后,我想获得返回的结果而不去 Completed 事件。请给我提意见。谢谢。
最佳答案
简单的回答:你不能。 Silverlight 中的所有内容都是异步的,因此无法在 client.RunHelloAsync(command)
调用后阻塞并等待结果。
长答案:有一些方法可以模拟以同步方式处理调用,但调用仍然是异步进行的。查看 this thread 以获得更多答案。
关于银光网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3402610/