Traditional Culture Encyclopedia - Weather forecast - How to call the webservice interface
How to call the webservice interface
Let's look at a simple weather forecast interface. First, enter the address of the weather forecast interface in the address bar: (/weatherService.asmx This is an example and can be modified according to personal needs).
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 the parameters you want to test first, click Call, and an xml file will appear. These are the results. Depending on the situation, we just need to 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 if he has any method, which should be consistent with the way we enter the link 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.
Protected void Button 1_Click (object sender, EventArgs e)
{
If (! String. IsNullOrEmpty (this. Text box 1. Text))
{
Meteorological service. WeatherWebServiceSoapClient service = new WeatherService。 WeatherWebServiceSoapClient();
string[]strweather info = service . getweatherbycityname(this。 Text box 1. Text);
StringBuilder str = new StringBuilder(" ");
Strait. AppendLine ("You can view the weather information in the following way:");
Foreach (string information in strwetherinfo)
{
Strait. AppendLine(info+" & lt; br/>);
}
This. Literal 1。 Text =str。 ToString();
}
}
Run the program and you will see the effect.
- Previous article:It's very hot. Tell me about it.
- Next article:In June 2022, five new cafes were opened in Bangkok.
- Related articles
- Dream that there is no water in the wells of other villages.
- Information about Qinghai-Tibet Railway
- Where does Sanya's fresh water come from? Can you tell me?
- Seeing Plum in Classical Chinese to Quench Thirst
- Where is a suitable place to travel in late September?
- Will it rain in Taizhou, Zhejiang tomorrow?
- What English words are used to express weather?
- What are the indigenous methods that formaldehyde is most afraid of?
- The weather is getting hotter and hotter, so pay attention to these aspects when blowing air conditioners during the epidemic period!
- How does Android 4.0.4 put ink weather on the desktop?