欢迎光临
我们一直在努力

股票报价的WebService(转天极网)之四-.NET教程,Web Service开发

建站超值云服务器,限时71元/月

创建 web应用程序用户<br>

<br>

下面创建一个web应用程序stockconsumer.aspx,它作为这个stockquote(股票报价) web服务的第一个用户。 <br>

<br>

  <%@ page language=&quot;c#&quot; %><br>

  <%@ import namespace=&quot;system.xml&quot; %><br>

  <%@ import namespace=&quot;quotes&quot; %><br>

<br>

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

<br>

  <html><br>

  <head><br>

  <script runat=server><br>

   // wire up the onclick event for a button <br>

   protected void button1_click(object sender, eventargs e)<br>

   {<br>

    file://create a object of the class dailystock (the proxy class)<br>

    dailystock ds = new dailystock();<br>

<br>

    // call the getquote method of the proxy class dailystock and <br>

    // pass the symbol string from the textbox <br>

    string res = ds.getquote(symbol.text);<br>

<br>

    // the returned string has values which are separated <br>

    // by commas.<br>

    // hence we split the returned string into parts <br>

    char[] splitter = {,} ;<br>

    string[] temp = res.split(splitter);<br>

<br>

    // check if the string array returned has more than one <br>

    // elements since if there are less than one elements <br>

    // then an exception must have been returned <br>

    if(temp.length &gt;1)<br>

     {<br>

      // the webservice returns a lot of information about the<br>

      // stock. we only show the relevant portions<br>

      // set the label to current index<br>

      curindex.text = &quot;current index :&quot;+temp[1]; <br>

<br>

      // set the label to current date time<br>

      curdate.text =&quot;last update on&quot;+temp[2]+&quot; at &quot;+temp[3]; <br>

     }<br>

    else<br>

     {<br>

      error.text = &quot;error :&quot;+res ; file://set the error label<br>

     }<br>

    }<br>

   </script><br>

<br>

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

<br>

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

<br>

  代码的其余部分<br>

<br>

  <body><br>

  <center><br>

  <h2>.net101 stock quote consumer </h2><br>

<br>

  <form runat=server ><br>

   <table border=1 celspacing=1><br>

    <tr><th>please enter the symbol below</th></tr><br>

    <tr><td><br>

    <asp:textbox id=symbol runat=server /> <br>

    <asp:button id=button1 text=&quot;get quote&quot; onclick=&quot;button1_click&quot; runat=server /><br>

    </td></tr><br>

    <tr><td><asp:label id=curindex runat=server /></td></tr><br>

    <tr><td><asp:label id=curdate runat=server /></td></tr><br>

    <tr><td><asp:label id=error runat=server /></td></tr><br>

   </table><br>

  </form><br>

<br>

  </center><br>

  </body><br>

  </html><br>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 股票报价的WebService(转天极网)之四-.NET教程,Web Service开发
分享到: 更多 (0)