简体   繁体   中英

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. 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.

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.

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!!

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. Otherwise, it will create APM and EAP endpoints. 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.

Your best bet is to try to reuse the WCF client proxy code in your projects; eg, put it in a Portable Class Library and use the generated TAP methods. If you can't get that to work, then put the client proxy in the PCL and create TAP wrappers for the APM endpoints .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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