下面就部署MVC项目到IIS6的过程做一次备注
演示项目中引用了一个Web service(主要根据地区邮编或地区名称来获取天气预报)http://www.webservicex.net/WeatherForecast.asmx?WSDL
第一步: 正式创建一MVC项目,本项目沿用上个示例,名称为MvcAppDemoFck。项目结构如下图:

第二步:添加web引用,这个与普通的web service没什么不同,输入地址 http://www.webservicex.net/WeatherForecast.asmx?WSDL
其他默认即可。如上图。
第三步:在Controller下添加新的Controller,名称为WeatherController,添加代码如下:

C# Code
[http://www.xueit.com]
public ActionResult Index()
{
return View();
}
public ActionResult GetWeather(string Id)
{
//if (string.IsNullOrEmpty(Id)) { return null; }
if (string.IsNullOrEmpty(Id)) { Id = "New York"; }
StringBuilder sb = new StringBuilder();
WeatherForecast wf = new WeatherForecast();
WeatherForecasts wfs = wf.GetWeatherByPlaceName(Id);
WeatherData[] wd = wfs.Details;
sb.AppendFormat("<B>Weather Forecast for {0}</B><br /><br />", wfs.PlaceName);
foreach (WeatherData d in wd)
{
if (!string.IsNullOrEmpty(d.WeatherImage))
{
sb.AppendFormat("<img src="{0}" >", d.WeatherImage);
sb.AppendFormat(" {0}", d.Day);
sb.AppendFormat(", High {0}F", d.MaxTemperatureF);
sb.AppendFormat(", Low {0}F<br />", d.MinTemperatureF);
}
}
Response.Write(sb.ToString());
return null;
}
并在 "public ActionResult Index{"处右键 Add View,新增一个View名称为GetWeather.aspx,即默认名称
精彩图集