【发布时间】:2014-08-17 12:27:19
【问题描述】:
我一直在尝试学习 WCF,并创建了 hello world 服务来查询值并返回结果。我为服务(windows phone)创建了一个客户端,向服务器发送一个值并显示结果。虽然我试图在我的 web 服务中返回字符串,但 windows phone 应用程序中方法的返回类型是 void 并且也是异步的。
public class Service1 : IService1
{
public string GetName(String PhoneNumber)
{
DBEntities Context = new DBEntities();
String Name = (from x in Context.Contacts
where x.Number.Equals(PhoneNumber)
selectx.Name).FirstOrDefault();
return Name;
}
...
}
在客户端:
private void Submit_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.Service1Client vv = new ServiceReference1.Service1Client();
vv.GetNameAsync(TextBox1.Text);
}
我的问题是,我怎样才能从异步方法中获得响应?
【问题讨论】: