1.首先在vs中新建项目
2.添加web引用....
3.输入WebService地址:http://88.148.29.54:8080/aio/services/WebServiceSample?wsdl最后点击“添加引用”
4.创建一个简单的form
5.编写按钮事件代码
6.最后点击调试运行,或按F5运行,通过点击按钮就可以看到调用WebService的运行结果了
![](https://i-blog.csdnimg.cn/blog_migrate/e954de4c4b472260c63e29126a40fd5a.jpeg)
2.添加web引用....
![](https://i-blog.csdnimg.cn/blog_migrate/d084c9e38cc41f2ab9f5d01a83d87647.jpeg)
3.输入WebService地址:http://88.148.29.54:8080/aio/services/WebServiceSample?wsdl最后点击“添加引用”
![点击查看原始大小图片](https://i-blog.csdnimg.cn/blog_migrate/9717cd7d7cb624e04aafe62970d20a01.jpeg)
4.创建一个简单的form
![](https://i-blog.csdnimg.cn/blog_migrate/3757c1c0828928897c6e4db173812938.jpeg)
5.编写按钮事件代码
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Net;
- using System.Windows.Forms;
- using WindowsApplication1.WebReference;
- namespace WindowsApplication1
- {
- public partial class Form1 : Form
- {
- WindowsApplication1.WebReference.WebServiceSampleImplService service = null;
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String str = "";
- try
- {
- str = service.say("Libin");
- }
- catch (Exception we)
- {
- str = we.Message;
- }
- //MessageBox.Show(str);
- textBox1.Text = str ;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- service = new WebServiceSampleImplService();
- label1.Text = "WS.url:" + service.Url + "\r\n";
- }
- private void button2_Click(object sender, EventArgs e)
- {
- String str = "";
- try
- {
- User user = new User();
- user.id = 1;
- user.name = "Libin";
- str = "userName:" + service.sayUserName(user);
- }
- catch (Exception we)
- {
- str = we.Message;
- }
- //MessageBox.Show(str);
- textBox1.Text = str;
- }
- private void button3_Click(object sender, EventArgs e)
- {
- String str = "";
- try
- {
- Object[] users = service.findUsers();
- for (int i = 0; i < users.Length; i++)
- {
- User user = (User)users[i];
- str += "id:"+user.id + " name:" + user.name + "\r\n";
- }
- }
- catch (Exception we)
- {
- str = we.Message;
- }
- //MessageBox.Show(str);
- textBox1.Text = str;
- }
- }
- }
6.最后点击调试运行,或按F5运行,通过点击按钮就可以看到调用WebService的运行结果了
![](https://i-blog.csdnimg.cn/blog_migrate/f54c882738a9ad34af9510867b609e77.jpeg)