2010-08-04 83 views
3

以下是我用来在SilverLight中使用Web服务的代码。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)之后,我想获得返回的结果而不需要完成事件。请建议我。谢谢。

+0

为什么你不能在完成的活动中做你需要的东西? – AnthonyWJones 2010-08-04 12:35:38

回答

3

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

长答案:有许多方法可以模拟以同步方式处理调用,但调用仍然是异步进行的。看看this thread了解更多答案。