C # How to Use winForm to call WebService remote interfaces,
C # How to Use winForm to call WebService remote interfaces
Create a WebService project use case
Add service reference
Add a webService address
Enter the namespace name
Main Code
Test successful
Download project code
Create a test project
Layout
1. Add service reference
2. Enter the WebService address in the address bar of the add service reference dialog box,
For example, https: // localhost: 6677/webservice1.asmx
3. Enter the namespace name or retain the default value.
4. Main test code:
myWebServiceTest.WebService1SoapClient myWebService = null; private void Form1_Load(object sender, EventArgs e) { myWebService = new myWebServiceTest.WebService1SoapClient("WebService1Soap"); } private void button1_Click(object sender, EventArgs e) { textBox1.Text = myWebService.HelloWorld(); } private void button2_Click(object sender, EventArgs e) { textBox2.Text = myWebService.GetStr(textBox3.Text); }
Code for accessing the WebService Server:
[WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public string GetStr(string name) { return this.HelloWorld() + "-->:" + name; }
5. Running result diagram: