C# WPF 基于soap的web引用
WPF的web引用
前言:项目需要是通过PLc获取数据后上传SAP系统,所以需要用到web引用,期间使用的是WPF,所以写一篇文章记录下来。
1.新建WPF(基于.NET Framework)
注意:不要建立使用.NET Core的,因为很多都不兼容,之前在这里踩坑太多了,不建议用,因为不支持web引用。

2.按步骤,在项目中创建web引用
项目–> 添加服务引用 --> 高级 --> web引用


3.根据提供的web接口url,输入url,创建web引用。
"http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"

4.实例化web引用后,发送数据。
注意:生成的引用类,需要结合这个接口的对接数据进行对应的参数输入等,需要自己摸索。
Weather.WeatherWebService w = new Weather.WeatherWebService();
//把webservice当做一个类来操作
string[] s = new string[23];//声明string数组存放返回结果
string city = this.sKey.Text.Trim();//获得文本框录入的查询城市
s = w.getWeatherbyCityName(city);
//以文本框内容为变量实现方法getWeatherbyCityName
if (s[8] == "")
{
MessageBox.Show("暂时不支持您查询的城市");
}
else
{
tst.Text = "";
for (int i = 0; i < 23; i++)
{
tst.Text += s[i] + "\r\n";
}
// tst.Text = s[1] + " " + s[6]+s[10];
}

浙公网安备 33010602011771号