文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页网页设计ASP实例 → 股票报价的WebService之四

股票报价的WebService之四

时间:2004/11/7 2:54:00来源:本站整理作者:蓝点我要评论(0)

创建 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>








相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 迅雷新手完全入门手册 asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法

人气排行 总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码