C # How to Use winForm to call WebService remote interfaces,

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.