WebService Simple Invocation Example

Source: Internet
Author: User

WebService is mainly some of the site for us to write a good way for us to call, of course, we can also write their own webservice, this article is mainly through a small instance, how to call WebService. Here are a few of the commonly used webservice call addresses.

Express Query Interface HTTP://WEBSERVICE.36WU.COM/EXPRESSSERVICE.ASMXIP query Interface Http://webservice.36wu.com/ipService.asmx Weather interface http ://webservice.36wu.com/weatherservice.asmx ID Query Interface http://webservice.36wu.com/IdCardService.asmx mobile phone Attribution interface/HTTP// Webservice.36wu.com/mobilephoneservice.asmx Translation Interface Http://webservice.36wu.com/TranslationService.asmx train time interface: http:/ /webservice.36wu.com/trainservice.asmx Stock Query Interface Http://webservice.36wu.com/StockService.asmx

Let's take a simple weather forecast interface. First, the address of the weather interface is entered into the Address bar: There will be a number of links with the method name and parameter description and so on. After reading, and then into the link can see the test, we can first write the parameters we want to test, click on the call, there will be an XML file, these are the results, depending on the situation we have to deal with the results as we want to do.
Here's how to call it in your project: Create a new Web project, click Add Reference Service, and then click OK.

This will be found in the Webconfig file a bit more nodes, and the Project class service references files more than a green thing. Can click to see what he has, should be and we in the browser input link method is consistent, the rest is how to call. Here is the specific code: This code value in WebForm first add lable, TextBox, button and literal each one. Then click the button.

        protected void Button1_Click (object sender, EventArgs e)        {            if (!string. IsNullOrEmpty (this. TextBox1.Text))            {                Weatherservice.weatherwebservicesoapclient service = new Weatherservice.weatherwebservicesoapclient ();                            string[] Strweatherinfo = Service.getweatherbycityname (this. TextBox1.Text);              StringBuilder str = new StringBuilder ("");              Str. Appendline ("You see weather information as follows:");              foreach (string info in Strweatherinfo)              {                  str. Appendline (info+ "<br/>");              }                This. Literal1.text =str. ToString ();            }        }

To run the program, enter the city you are viewing: Click the button:

OK, basically, a webservice call is done.

WebService Simple Invocation Example

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.