网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.无组件文件上传代码实例.
.用asp.net写的论坛程序--论坛主页.
.三级下拉框连动的数据库版.
.利用ASP存取各种常用类型数据库(.
.WEB环境下打印报表的crystal的解.
.图片数据的存和取示例.
.SQL SERVER结构浏览器.
.用Asp+XmlHttp实现RssReader功能.
.数字和字母组合并生成图片的验证.
.用EasyMailObject组件处理Exchan.
.中文虚拟域名实现(1) (环境:中文.
.FrontPage创建HTML/ASP混合页面.
.一个简单的网上书城的例子(二).
.一个功能完善的专栏管理的程序-&.
.使用VB编写纯ASP程序.
.调试 ASP 中使用的 Visual Basic.
.用ASP开发试题库与在线考试系统(.
.利用ASP实现对表的分页浏览(下).
.二文件上传,才30行代码.
.用asp.net写的论坛程序--上贴保存.

股票报价的WebService之四

发表日期:2001-5-25


创建 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之三 人气:10312
下一篇:股票报价的WebService之五 人气:11692
浏览全部WebService的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐