2010-08-04 81 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瞭解更多答案。