在Universal应用程序中调用WCF服务

时间:2016-04-26 08:09:27

标签: c# wcf win-universal-app

我试图在Windows通用应用程序中调用WCF服务,显然你只能异步调用函数“GetMoments”。但我无法填写ObservableCollection。

EndpointAddress address = new EndpointAddress("net.tcp://localhost:9999/DeliveryService");

NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);

DeliveryClient client = new DeliveryClient(binding, address);

Task<ObservableCollection<DeliveryMoment>> moments = client.GetMomentsAsync();
moment.Wait()只是永远等待并调用moment.Start()是不允许的,这会引发异常。如何填写收藏品?

1 个答案:

答案 0 :(得分:1)

请你用await / async模式进行测试吗?例如:

public async void Load()
{
      EndpointAddress address = new EndpointAddress("net.tcp://localhost:9999/DeliveryService");

      NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);

      DeliveryClient client = new DeliveryClient(binding, address);

      ObservableCollection<DeliveryMoment> moments = await client.GetMomentsAsync();
}