首 页 | 精品电影 | 音乐天堂 | 在线游戏 | Flash MTV | 三湘书屋 | 幽默笑话 | 三湘图库 | 美女写真 | IT知识库 | QQ贴图 | 加入书签

网页制作网络编程图形图象操作系统冲浪宝典软件教学网络安全认证考试通信技术电子商务业内动态书籍教程原码

最近更新 文章分类 多媒体类 精品软件

本站搜索:
您的位置:三湘时空 -> IT知识库 -> 文章分类 -> ASP实例 -> 股票报价的WebService之四  
股票报价的WebService之四


文章类别:ASP实例 来源: 作者: 发表日期:2005-10-4 字体:[ ]

小游戏 | 在线影院 | 幽默笑话 | 源码下载 | Flash MTV | 音乐试听 | 书屋 | 美女写真

创建 Web应用程序用户

下面创建一个Web应用程序StockConsumer.aspx,它作为这个StockQuote(股票报价) Web服务的第一个用户。

  <%@ Page language="C#" %>
  <%@ Import Namespace="System.Xml" %>
  <%@ Import Namespace="Quotes" %>

  以上引入必要的名称空间。要记住也要引入 Quotes名称空间,它是代理库的名称空间。

  <html>
  <head>
  <script runat=server>
   // Wire up the onClick event for a button
   protected void button1_Click(object sender, EventArgs e)
   {
    file://Create a object of the class DailyStock (the proxy class)
    DailyStock ds = new DailyStock();

    // Call the GetQuote method of the proxy class DailyStock and
    // pass the symbol string from the textbox
    string res = ds.GetQuote(symbol.Text);

    // The returned string has values which are separated
    // by commas.
    // Hence we split the returned string into parts
    char[] splitter = {','} ;
    string[] temp = res.Split(splitter);

    // Check if the string array returned has more than one
    // elements since if there are less than one elements
    // then an exception must have been returned
    if(temp.Length >1)
     {
      // The WebService returns a lot of information about the
      // stock. We only show the relevant portions
      // Set the label to current Index
      curindex.Text = "Current Index :"+temp[1];

      // Set the label to current Date Time
      curdate.Text ="Last Update on"+temp[2]+" at "+temp[3];
     }
    else
     {
      error.Text = "Error :"+res ; file://set the error label
     }
    }
   </script>

以上ASP.NET页面代码中,首先对Web 服务DailyStock进行例示。由于已经生成了代理库,因此Web服务的调用方法与其它任何库的调用方法都相同。调用DailyStock 类的GetQuote()方法后,将返回一个字符串,其中包含了以逗号分隔的列表符号的完整信息。

  我们将限制显示给客户的信息为只显示当前指数和所报告指数的日期/时间。为了将字符串分成若干不同的部分,这里使用了字符串类的Split方法,在出现逗号的地方将字符串分割成部分。并且,将分割开的字符串组成数组之后,再使用相关的数值为Web页面设置不同的标签。

  代码的其余部分

  <body>
  <center>
  <h2>.NET101 Stock Quote Consumer </h2>

  <form runat=server >
   <table border=1 celspacing=1>
    <tr><th>Please enter the symbol below</th></tr>
    <tr><td>
    <asp:textbox id=symbol runat=server />
    <asp:button id=button1 text="Get Quote" onClick="button1_Click" runat=server />
    </td></tr>
    <tr><td><asp:label id=curindex runat=server /></td></tr>
    <tr><td><asp:label id=curdate runat=server /></td></tr>
    <tr><td><asp:label id=error runat=server /></td></tr>
   </table>
  </form>

  </center>
  </body>
  </html>
上一篇:股票报价的WebService之三 下一篇:股票报价的WebService之五
本栏目热门文章
·用EasyMailObject组件处理Exchange邮件源代码(6 2005-10-4
·用EasyMailObject组件处理Exchange邮件源代码(5 2005-10-4
·用EasyMailObject组件处理Exchange邮件源代码(1 2005-10-4
·用EasyMailObject组件处理Exchange邮件源代码(2 2005-10-4
·用EasyMailObject组件处理Exchange邮件源代码(3 2005-10-4
·用EasyMailObject组件处理Exchange邮件源代码(4 2005-10-4
·用EasyMailObject组件处理Exchange邮件源代码(7 2005-10-4
·通过ASP与ACCESS数据库建立连接(附源码)(2) 2005-10-3
·调用winzip命令行对上传的多个文件打包压缩 2005-10-4
·多个域名后缀同时查询的域名查询系统 2005-10-31
新近更新文章
·asp简单的ajax留言板(采用三层模式) 2006-5-28
·ASPImage组件的实现过程 2005-12-20
·多个域名后缀同时查询的域名查询系统 2005-10-31
·asp提供在线文章翻译的功能 2005-10-4
·实例讲解ASP实现抓取网上房产信息 2005-10-4
·纯ASP代码之公历转农历实现(含属相) 2005-10-4
·纯ASP代码之公历转农历实现(含属相)--例子代码 2005-10-4
·用Asp+XmlHttp实现RssReader功能 2005-10-4
·菜鸟详听ASP中也能解压缩rar文件 2005-10-4
·采用XMLHTTP编写一个天气预报的程序 2005-10-4
首 页 | 软件发布 | 广告联系 | 下载帮助 | 意见反馈 | 网站地图
  CopyRight? 2002-2004 WWW.SXSKY.NET? All Rights Reserved
三湘时空 站长QQ:82675303 Email: