Traditional Culture Encyclopedia - Weather forecast - How to call a method in the webservice interface

How to call a method in the webservice interface

Webservice is mainly a method written by some websites for us to call. Of course, we can also write our own webservice. This paper mainly discusses how to call webservice through a small example. Firstly, the calling addresses of several commonly used webservice are given.

Let's look at a simple weather forecast interface. Enter the address of the weather forecast interface in the address bar first: there will be some method names and parameter descriptions with links. After reading it, you can go to the link to watch the test. You can write in the parameters we want to test first, click Call, and an xml file will appear. These are the results. Depending on the situation, we can process the results into what we want.

Let's talk about how to call it in the project: create a new web project, then click Add Reference Service as shown in the figure, and then click OK.

In this way, you will find that there are many nodes in the webconfig file, and there is a green thing in the service reference file in the project class. You can click to see what method he has, which should be consistent with the way we enter links in the browser, and the rest is how to call it. The specific code is as follows: this code value first adds a Lable, a TextBox, a Button and a Literal to the webForm. Then click the button.

Run the program and enter the city to view: click the button, as shown: