在 Windows Phone 应用程序中使用 WCF 服务:方法返回无效
问题描述:
我有 WCF 服务
当我在 Windows Phone 应用程序中添加服务引用"时,一切看起来都不错,但方法返回无效.例如,我在 WPF 应用程序中测试了该服务器,它可以工作并返回我需要的内容,但在 wp 7/8 应用程序中则不然.当然这个 WCF 的基本功能是返回数据,所以 void 方法对我来说完全没用.
When I "Add Service Reference" in my windows phone application everything looks good but methods return void. I tested this server for example in WPF app and it works and returns what I need but in wp 7/8 app not. Ofcourse the basic functionality of this WCF is to return data so void methods are totally useless for me.
答
您可以使用服务 Async
和 Completed
事件.服务将在 completed 事件如
You can use service Async
and Completed
events.Service will return data in completed
event like
ServiceReference1.Service1Client clientForTesting = new ServiceReference1.Service1Client();
clientForTesting.GetDataCompleted += new EventHandler<ServiceReference1.GetDataCompletedEventArgs>(TestCallback);
clientForTesting.GetDataAsync(testValue);