WCFclient operation only Async .Net core 2.0

There is a way to generate synchronous methods in your .NET core project in Visual Studio 2019.

Wizard that adds WCF web service reference to your .NET core project has an option Generate Synchronous Operations in the third step, Client Options:

enter image description here

Make sure you check it as it is unchecked by default.


Your client does not expose synchronous method but that shouldn't be a problem for you.

Instead of asynchronously calling the method just do this:

response = SystemClient.SearchAirportsAsync(credentials, SystemHelperLanguageTypes.English, SystemHelperSearchTypes.CodeSearch, "ist").Result;

This will call the method synchronously as it will block the call. Check John Skeets answer here.

That being said I would recomend you use the async method that is provided. To support that you would have to change the Action signature to this:

public async Task<IActionResullt> Index()
{
   SystemClient SystemClient = new SystemClient();
   Credential credential = new Credential();
   credential.UserName = "username";
   credential.UserPassword = "****";

   var response1 = await SystemClient.SearchCountriesAsync(credentials, SystemHelperLanguageTypes.English, SystemHelperSearchTypes.CodeSearch, "TR");
   var response = await SystemClient.SearchAirportsAsync(credentials, SystemHelperLanguageTypes.English, SystemHelperSearchTypes.CodeSearch, "ist");

   //Do whatever you do with those responses

   ViewBag.Language = "ar";
   return View();
}