银光网络服务

标签 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) 之后,我想获得返回的结果而不去 Completed 事件。请给我提意见。谢谢。

最佳答案

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

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

关于银光网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3402610/

相关文章:

Silverlight 按钮 - 悬停时更改前景色

silverlight - 如何在 WCF Web 服务中返回对象?

.net - 您对 Silverlight 的主要功能要求是什么?

silverlight-3.0 - 银光 3.0 : How do I get grid children by x:Name?

silverlight - 将前景转换器添加到 xaml 中的 DatagridTextColumn

.net - Visual Studio 2010 在 Release模式下构建 silverlight 应用程序时显示错误

silverlight - ListPicker 中的按钮

silverlight - 您可以为每个后备字体指定不同的字体大小吗?

silverlight-3.0 - Silverlight中最干净的单击+双击处理?

silverlight - 如何编写离线Silverlight应用程序?