Silverlight Web服务

时间:2010-08-04 04:38:53

标签: silverlight silverlight-3.0

以下是我在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)之后,我希望得到返回的结果,而不是去完成事件。请建议我。谢谢。

1 个答案:

答案 0 :(得分:3)

简单回答:你做不到。 Silverlight中的所有内容都是异步的,因此在client.RunHelloAsync(command)调用之后无法阻止并等待结果。

答案很长:有一些方法可以模拟以同步方式处理调用,但调用仍然是异步调用的。请查看this thread以获得更多答案。