1-添加服务引用;
(1)工程 - Service References - 添加服务引用;
(2)在“添加服务引用”中输入Webservice网站发布地址,并敲回车或点击“转到”;
(3)调用代码编写
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WebServiceTestApp.ServiceReference1;//添加引用 namespace WebServiceTestApp { public partial class Form1 : Form { ServiceReference1.Service1SoapClient myWebService = null;//设置变量 public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { myWebService = new ServiceReference1.Service1SoapClient("Service1Soap");//实例化变量 } private void btnUpLoadCycleTime_Click(object sender, EventArgs e) { //test string SerialNumber = "160719070002873"; string StationName = "3120"; string MachineName = @"http://xx.xx.xx.xxx:8001/Service.asmx?"; string Employee = "user"; string Password = "123"; float CycleTime = 0; bool Result = false; DataTable ChildSNList = null; string Message = String.Empty; //调用Webservice方法如下 ServiceReference1.Service1SoapClient ser1 = new ServiceReference1.Service1SoapClient("Service1SoapClient"); myWebService.UpLoadCycleTime(SerialNumber, StationName, MachineName, Employee, Password, CycleTime, out Message); } } }
2-添加Web引用
(1)工程添加Webservice方法如下
(2)C#调用Webservice代码实现
private void btnStationManage_Click(object sender, EventArgs e) { //test WebReference.Service1 webservice = new WebReference.Service1(); //测试接口过站Json如下: string strJson = "[{\"serialnumber\":\"999919250000001\"}]"; DataTable Output_table = null; string result = String.Empty; Output_table = webservice.Station_Manage(strJson, out result); //测试前进站检查Json如下: string strJson2 = "[{\"serialnumber\":\"999919250000001\"}]"; DataTable Output_table2 = null; string result2 = String.Empty; Output_table2 = webservice.Station_Manage(strJson2, out result2); }
3-待续
4-待续