WCFclient 仅操作 Async .Net core 2.0 [英] WCFclient operation only Async .Net core 2.0

查看:24
本文介绍了WCFclient 仅操作 Async .Net core 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 asp.net core 2.0 中的 wcf 服务端点添加到连接的服务,然后我尝试使用它,但是对于客户端,只有以 ..async 结尾的函数

I added wcf services end point in asp.net core 2.0 to connected services and then I try to use that but with client there is only functions which ended with ..async

我不想使用 ...async.但是没有 .async 就没有功能

I don't want to use ...async.But there is no function without .async

这有什么问题?我该怎么办?

What is problem with this?What should I do?

而不是使用那个

 var response = SystemClient.SearchCountriesAsync(....

我想用那个

 var response = SystemClient.SearchCountries(...

但它给出了那个错误

错误 CS1061SystemClient"不包含SearchCountries"的定义,并且找不到接受SystemClient"类型的第一个参数的扩展方法SearchCountries"(您是否缺少 using 指令或程序集引用?)

Error CS1061 'SystemClient' does not contain a definition for 'SearchCountries' and no extension method 'SearchCountries' accepting a first argument of type 'SystemClient' could be found (are you missing a using directive or an assembly reference?)

推荐答案

您的客户端没有公开同步方法,但这对您来说应该不是问题.

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;

这将同步调用该方法,因为它会阻止调用.在此处查看 John Skeets 的回答.

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

话虽如此,我建议您使用提供的异步方法.为了支持这一点,您必须将 Action 签名更改为:

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();
}

这篇关于WCFclient 仅操作 Async .Net core 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆