This article WebService data source: Http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
China Meteorological Bureau http://www.cma.gov.cn/
Article reference article: http://zhangkui.blog.51cto.com/1796259/497324 Zhangkui's Blog
Start this article:
1, the creation of asp.net MVC procedures, as the call WebService client (using WebForm, WinForm the same reason);
2, add a controller, named GetWeather
3, add "service Reference", to find the service set a namespace, I used here is Servicereferenceweather
4, the above can be seen after completion
5, open the controller, 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, I use the Razor template engine, with ASPX is the same
7, the default view of the code to replace the following code (in fact, some HTML and CSS, you can write yourself)
@{Layout = null;} <! DOCTYPE html>
8. Change the default route of ASP.net MVC to controller and action for this case
Press F5 to run the program and you can see:
Input: such as Yangzhou
The end of this article
For more data and help, you can access: Http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
The string[] array returned by this webservice contains the following data, which can be accessed by index (as with the index access Viewdata.model in this article):