简体   繁体   English

Win8到WP App异步/等待对话

[英]Win8 to WP App async/await conversation

In the process of converting a Windows 8 app to Windows Phone but encountering a problem with the WCF connections and asynchronous communication. 在将Windows 8应用程序转换为Windows Phone的过程中,但遇到WCF连接和异步通信问题。 To summarise, I am trying to call a WCF service which connects to a Ms SQL Server but receive “cannot await void” for all the “await serviceClient.getEmployeesAsync();” or similar. 总而言之,我正在尝试调用一个WCF服务,该服务连接到Ms SQL Server,但对于所有“ await serviceClient.getEmployeesAsync();”或类似的消息都收到“无法等待作废”。

What is the simplest way to solve this problem as I have quite a few methods similar to this which work fine in the Windows 8 app but not Windows Phone app. 解决此问题的最简单方法是什么,因为我有很多与此类似的方法都可以在Windows 8应用程序中正常运行,但在Windows Phone应用程序中却无法正常工作。

private async void btnGetAllStaff_Click(object sender, RoutedEventArgs e)
    {
        //Create a client object to access the service
        DataProvider.DataProviderClient serviceClient = new DataProvider.DataProviderClient();

        //Get the staff objects from the service
        ObservableCollection<DataProvider.Employee> employees = await serviceClient.getEmployeesAsync();

        //Add the objects to the list view
        foreach (DataProvider.Employee employee in employees)
        {
            lstStaff.Items.Add(employee.FirstName+" "+employee.LastName);
        }
    }

I should add that I am new to WCF and network programming in general!! 我应该补充一点,我是WCF和网络编程的新手!!

Thanks 谢谢

The WCF proxy generator built-in to Visual Studio will generate TAP methods , but only if it knows the client platform supports async natively. Visual Studio内置的WCF代理生成器将生成TAP方法 ,但前提是它知道客户端平台本机支持async Otherwise, it will create APM and EAP endpoints. 否则,它将创建APMEAP端点。 What you're seeing is that your client proxy method ending in Async is TAP on the Windows Store platform, but EAP on the Windows Phone platform. 您会看到,以Async结尾的客户端代理方法在Windows Store平台上是TAP,而在Windows Phone平台上是EAP。

Your best bet is to try to reuse the WCF client proxy code in your projects; 最好的选择是尝试在项目中重用WCF客户端代理代码。 eg, put it in a Portable Class Library and use the generated TAP methods. 例如,将其放在可移植类库中并使用生成的TAP方法。 If you can't get that to work, then put the client proxy in the PCL and create TAP wrappers for the APM endpoints . 如果无法正常工作,则将客户端代理放入PCL并为APM端点创建TAP包装器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM