I have a ASP.NET web service (.asmx) that is called from client side with JavaScript.
Let say that the web service has a web method with the name "GetTotalMovies()". This web method will return an int with the number of movies in a specific channel on YouTube.
When this web method is called it will do a http request to the YouTube REST API to get how many movies a specific channel has and then return it to the client that called "GetTotalMovies()".
The call the the YouTube REST API is pretty slow so I want to do this asynchronous with this "pseude" code:
private async Task<int> GetTotalMoviesFromYouTubeApi()
{
using(var client = new WebClient()) {
return await client.DownloadStringAsync(_uri);
}
}
And here is my web method that is called from the client:
[WebMethod]
public int GetTotalMovies() {
return (int)await PostDataToYouTubeApi(s);
}
This will not work since I use the await keyword in the method GetTotalMovies when the method is not async.
But if I change the method to async I need to return Task from the method. And when I change this it will be really messy when JavaScript call this function.
I am stuck, I don't really now how to go further. Help! :)