添加WEB serverice服务类中的方法报错 “Weather.GetWeather()”: 并非所有的代码路径都返回值什么意思

javaPie 2012-03-14 11:42:11
public string GetWeather()
{
public string GetWeather(string city)
{
string weatherhtml = String.Empty;
string mycity=System.Web.HttpUtility.UrlEncode(city,System.Text.UnicodeEncoding.GetEncoding("GB2312"));

HttpWebRequest webrt=(HttpWebRequest)WebRequest.Create("http://php.weather.sina.com.cn/search.php?city="+mycity);
HttpResponse webrs=(HttpResponse)webrt.GetResponseStream();

Stream stream=webrs.GetResponseStream();
StreamReader srm=new StreamReader(stream,System.Text.Encoding.Default);
weatherhtml=srm.ReadToEnd();

srm.Close();
stream.Close();
webrs.Close();

int start = weatherhtml.IndexOf("城市天气 begin");
int end=weatherhtml.IndexOf("城市天气 end");
return weatherhtml.Substring(start+14,end-start);
}
}
还有一个错误错误 6 “System.Web.HttpResponse”不包含“GetResponseStream”的定义,并且找不到可接受类型为“System.Web.HttpResponse”的第一个参数的扩展方法“GetResponseStream”(是否缺少 using 指令或程序集引用?)
...全文
186 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
三石-gary 2012-03-14
  • 打赏
  • 举报
回复
第一个问题:意思就是说不能有返回值。。别用return 给它一个返回值;
第二个问题:你引入它对应的命名空间了?
javaPie 2012-03-14
  • 打赏
  • 举报
回复
[Quote=引用楼主 evilcry2012 的回复:]
public string GetWeather()
{
public string GetWeather(string city)
{
string weatherhtml = String.Empty;
string mycity=System.Web.HttpUtility.UrlEncode……
[/Quote] 能解答下吗
javaPie 2012-03-14
  • 打赏
  • 举报
回复
需要返回值
protected void Button1_Click(object sender, EventArgs e)
{
Weather myweather = new Weather();
Label1.Text = myweather.GetWeather(TextBox1.Text);
}
它对应的命名空间是什么?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧