国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

利用WebService制作股票報價4

2024-07-21 02:15:26
字體:
來源:轉載
供稿:網友
,歡迎訪問網頁設計愛好者web開發。創建 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>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富顺县| 新宁县| 霍邱县| 尖扎县| 德保县| 渝中区| 云龙县| 汉中市| 泗洪县| 台安县| 桦南县| 宁阳县| 丽江市| 河源市| 扎囊县| 泽普县| 定日县| 乌兰察布市| 拜城县| 彰武县| 达州市| 威海市| 永修县| 桐城市| 兴安盟| 同仁县| 通州区| 西青区| 辉县市| 慈利县| 浮梁县| 广东省| 河南省| 莱芜市| 客服| 灵山县| 略阳县| 汉阴县| 从江县| 固阳县| 台北市|