一、建立WebService
1:新建一个ASP.NET项目
![](https://img-blog.csdnimg.cn/img_convert/d9d6414a79d5580c95843c46621bee27.png)
2:添加WebService
![](https://img-blog.csdnimg.cn/img_convert/16947bcc72cb48cfa165abcc968d4d2a.png)
3:写入两个简单的方法(方法上面一定要加[WebMethod]特性)
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
[WebMethod]
public int Sub(int a, int b)
{
return a - b;
}
3:发布到文件夹
![](https://img-blog.csdnimg.cn/img_convert/0a5889f2d5ca60a55866debbaa79afd2.png)
4:打开IIS 配置网站信息(物理路径为刚刚发布的WebService文件夹路径)
![](https://img-blog.csdnimg.cn/img_convert/12fea91cd4a56125350498a403fbd309.png)
二、使用WebService
1:新建项目,在引用处添加服务器引用
![](https://img-blog.csdnimg.cn/img_convert/1f2f037a08a2e0363e68f5ac928d1a42.png)
2:在namespace中using刚刚引用的WebService。
private void button1_Click(object sender, EventArgs e)
{
IndexSoapClient indexSoapClient = new IndexSoapClient();
int res= indexSoapClient.Add(20, 10);
MessageBox.Show(res.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
indexSoapClient = null;
}
即可调用成功!