The data source of WebService: http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
China Meteorological Administration http://www.cma.gov.cn/
This article reference article: http://zhangkui.blog.51cto.com/1796259/497324 zhangkui blog
Start this article:
1. Create an Asp.net MVC program as the client that calls WebService (using webform and winform in the same way );
2. Add a controller named getweather.
3. Add "service reference" and set a namespace for the service. Here I use servicereferenceweather.
4. After completing the preceding steps, you can see
5. Open the controller and add the following code:
public ActionResult GetWeather() { return View(); } [HttpPost] public ActionResult GetWeather(FormCollection formCollection) { string cityName = formCollection["txtCityName"]; ServiceReferenceWeather.WeatherWebServiceSoapClient w = new WeatherWebServiceSoapClient("WeatherWebServiceSoap"); string[] res = new string[23]; res = w.getWeatherbyCityName(cityName); ViewData.Model= res; return View(); }
6. Add a view for the getweather controller. The Razor template engine I use here is the same as Aspx.
7. Replace the default view code with the following code (in fact, some HTML and CSS, you can write them by yourself)
@ {Layout = NULL ;}<! Doctype HTML>
8. Change the default route of Asp.net MVC to the Controller and action suitable for this case.
Press F5 to run the program. You can see:
Input: for example, Yangzhou
End of this Article
For more data and help, visit: http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
The string [] array returned by the WebService contains the following data, which can be accessed using indexes (as in this article, viewdata. model is accessed using indexes ):