问题
I'am trying to consume a wcf in windows 8: My code to consume the method generated by the WCF service:
public System.Threading.Tasks.Task<Maquette_MyAirport_Win8.FlightService.CitiesResponse>
GetAllCitiesAsync(Maquette_MyAirport_Win8.FlightService.BaseRequest request)
{
return base.Channel.GetAllCitiesAsync(request);
}
is
public testproxy()
{
_client = new FlightInfoServiceClient(Maquette_MyAirport_Win8.FlightService.FlightInfoServiceClient.EndpointConfiguration.wsHttpBindingConfiguration);
BaseRequest req = new BaseRequest();
System.Threading.Tasks.Task<Maquette_MyAirport_Win8.FlightService.CitiesResponse> CitiesResponse = _client.GetAllCitiesAsync( new BaseRequest());
CitiesResponse.ContinueWith(task => citiesL = task.Result.Cities.FirstOrDefault(););
}
The status of the task citiesResponse is "WaitingForACtivation" and Result="Not yet Computed"
How can I Activate the task and how can i obtain the result??
回答1:
Don't you have to add async and await to get the result type instead of Task type??
It should be something like this:
var result = await _client.GetAllCitiesAsync( new BaseRequest());
And in the method you should add async
来源:https://stackoverflow.com/questions/12508643/how-to-activate-task-in-c