【发布时间】:2014-09-16 14:24:50
【问题描述】:
我有返回对象集合的 WCF 服务。
他正在使用我开始的代码(我不确定它是否正确):
List<AxaptaServiceReference.Inspection> remoteInspections = (await proxy.GetInspectionsByInspectorAsync(App._winlogin)).ToList<AxaptaServiceReference.Inspection>();
我需要将此调用移至单独的类:
public class AxGateWay
{
public async List<AxaptaServiceReference.Inspection> GetInspections(string _inspector)
{
AxaptaServiceReference.AxaptaWebServiceClient proxy = new AxaptaServiceReference.AxaptaWebServiceClient();
List<AxaptaServiceReference.Inspection> remoteInspections = (await task).ToList<AxaptaServiceReference.Inspection>();
return remoteInspections;
}
}
编译器告诉我异步方法必须返回任务(或任务)。
如果我想确保我的代码在 Web 服务返回数据时等待,我需要如何重写我的方法以及该方法调用必须如何。
【问题讨论】:
标签: c# wcf asynchronous async-await windows-8.1