代码改变世界

使用webservice获得天气,基金,股票等信息

  Virus-BeautyCode  阅读(2224)  评论(2编辑  收藏  举报
protected void Button1_Click(object sender, EventArgs e)
    
{
        cn.com.webxml.www.WeatherWebService weather 
= new cn.com.webxml.www.WeatherWebService();
        
string[] weathers = weather.getWeatherbyCityName("58367");
        
this.TextBox1.Text = weathers[10].ToString();
        cn.com.webxml.www.ChinaOpenFundWS fund 
= new cn.com.webxml.www.ChinaOpenFundWS();
        DataSet ds
= fund.getFundCodeNameDataSet();
        
this.GridView1.DataSource = ds.Tables[0].DefaultView;
        
this.GridView1.DataBind();
        cn.com.webxml.www.ChinaStockSmallImageWS stock 
= new cn.com.webxml.www.ChinaStockSmallImageWS();
        
byte[] b = stock.getSmallImageByte("sh000001"byte.MaxValue);
        Random random 
= new Random();

        
string imageName=random.Next().ToString()+ ".jpg";
        
string myUrl = HttpContext.Current.Server.MapPath(this.Request.ApplicationPath) + imageName;
        FileStream fs 
= new FileStream(myUrl, FileMode.OpenOrCreate);
        BinaryWriter w 
= new BinaryWriter(fs);
        w.BaseStream.Write(b, 
0, b.Length);
        w.Flush();
        w.Close();

        
this.Image1.ImageUrl = Context.Request.ApplicationPath  + imageName;
        System.Drawing.Bitmap bitmap 
= new System.Drawing.Bitmap(myUrl);
        
this.Image1.Width = bitmap.Width;
        
this.Image1.Height = bitmap.Height;
    }
给大家介绍一个很好的网站,提供了一些常用的web服务,例如时刻表,天气,基金,股票,IP等,大家可以自己去看看。
http://www.webxml.com.cn/zh_cn/web_services.aspx
下面我演示一个例子,获取天气,基金列表和股票走势图,具体的基金值需要联系网站,用他分配的用户名做参数才可以访问。


编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示