WCFclient仅操作Async .Net core 2.0

编程入门 行业动态 更新时间:2024-10-24 00:28:09
本文介绍了WCFclient仅操作Async .Net core 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I added wcf services end point in asp 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(...

但出现错误

错误CS1061'SystemClient'不包含'SearchCountries'的定义,也没有扩展方法'SearchCountries'接受类型为'SystemClient'的第一个参数可以找到(您是否缺少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;

这将同步调用该方法,因为它将阻止该调用。在此处查看。

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

话虽如此,我建议您使用提供的async方法。为了支持这一点,您必须将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

本文发布于:2023-11-14 00:48:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作   Async   WCFclient   core   Net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!