.net5调用WebService简单事例
1. 创建 .net5控制台项目:
dotnet new console -o WebServiceConsole
2. 添加全局工具
dotnet tool install --global dotnet-svcutil --version 2.0.3
3. 执行 dotnet restore
dotnet restore
4. 以获取国内手机号码归属地信息为例(网址:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx),生成代理类
dotnet svcutil http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
5. 再次执行 dotnet restore,然后修改 Program.cs
using System; using System.ServiceModel; using System.Threading.Tasks; using ServiceReference; namespace WebServiceConsole { class Program { static async Task Main(string[] args) { var client = new MobileCodeWSSoapClient(MobileCodeWSSoapClient.EndpointConfiguration.MobileCodeWSSoap); //// 获得国内手机号码归属地数据库信息 //var x = await client.getDatabaseInfoAsync(); //foreach(var str in x) //{ // Console.WriteLine(str); //} // 获得国内手机号码归属地省份、地区和手机卡类型信息 var y = await client.getMobileCodeInfoAsync("1388888", ""); Console.WriteLine(y); Console.ReadLine(); } } }
6. 保存,Ctrl+F5,然后结果:
1388888:云南 昆明 云南移动合家欢卡
这是一个简单的事例。
参考:
https://www.qiufengblog.com/articles/dotnet-core-webservice.html
http://www.webxml.com.cn/zh_cn/index.aspx (http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx)
https://docs.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-svcutil-guide?tabs=dotnetsvcutil2x
https://www.cnblogs.com/myzony/p/9547254.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?