快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

股票报价的WEBSERVICE之四

创建 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>
返回类别: 教程
上一教程: 对数据库中的记录用上一条下一条显示(二)
下一教程: 解决使用ASP无法连接ORACLE 9I数据库的问题

您可以阅读与"股票报价的WEBSERVICE之四"相关的教程:
· 股票报价的WEBSERVICE之三
· 股票报价的WEBSERVICE之二
· 股票报价的WEBSERVICE之一
· 股票报价的WEBSERVICE之五
· 构建你的网站新闻自动发布系统之四
    微笑服务 优质保证 索取样品