C#
  Home arrow C# arrow Page 3 - Build a C# Stock Quote WebService Part 1/2
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Build a C# Stock Quote WebService Part 1/2
By: Peter Bromberg
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2003-01-06

    Table of Contents:
  • Build a C# Stock Quote WebService Part 1/2
  • Building the Ticker
  • Building the Ticker (cont'd)
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Build a C# Stock Quote WebService Part 1/2 - Building the Ticker (cont'd)


    (Page 3 of 4 )

    We then loop through each line from the stream, building our return XML Document string, but first we also "clean out" some of Yahoo's "noise" (quote) characters using the StringBuilder class:

    StringBuilder strContent = new StringBuilder("");
    sTemp+="";
    for(int i=0;i<=symbols.GetLength(0)-1;i++)
    {
    sContentTemp = strm.ReadLine();
    strContent.Append(sContentTemp);
    for (int k=0;k<=strContent.Length-1;k++)
    {
    // remove the char from StringBuilder string if contains quite symbol (\")
    if(strContent[k].ToString()=="\"")
    strContent.Remove(k,1);
    }
    // now should have clean string, create array of elements
    string[] contents=strContent.ToString().Split(delim2);
    // Clear out our StringBuilder for next iteration
    strContent.Remove(0,strContent.Length);
    sTemp+="";
    sTemp+="" +contents[0]+"";
    sTemp+="" +contents[1]+"";
    sTemp+=""+contents[2]+"";
    sTemp+="";
    sTemp+=""+contents[4]+"";
    sTemp+=""+contents[5]+"";
    sTemp+=""+contents[6]+"";
    sTemp+=""+contents[7]+"";
    sTemp+=""+contents[8]+"";
    sTemp+=""+contents[9]+"";
    sTemp+=""+contents[10]+"";
    sTemp+=""+contents[11]+"";
    sTemp+=""+contents[13]+"";
    sTemp+=""+contents[14]+"";
    sTemp+=""+contents[15]+"";
    sTemp+=""+contents[16]+"";
    sTemp+="
    ";
    result+=sTemp;
    sTemp="";
    }
    //Close the stream from the server
    strm.Close();
    result += "
    ";
    }

    Finally, we catch any exceptions, and return our result stream of valid XML (or "exception", as the case may be):

    catch(Exception)
    {
    //If exception occurred, provide user message
    result="exception";
    }
    //Return StockQuote(s) or Exception
    return result ;
    }
    }

    Now if you simply load this page in your browser, the .NET Platform will compile and cache it into IL (Intermediate Language) and you can see the default "Webservice Discovery Channel" page, as I like to call it. At this point, you should be able to pass the input parameters on the querystring, use a SOAP method call, or even use xmlHTTP to send the parameters to the service and get back the well-formed XML response document containing your quotes. Just be sure to delimit your quote symbols with spaces, as that's what Yahoo's server expects. Your StockQuote WebService class will take care of the rest. If you append "?SDL" to your URL to the service, you'll get a complete Service Description Language document that completely describes your webservice, its method(s), parameters and types.

    More C# Articles
    More By Peter Bromberg


     

    C# ARTICLES

    - Introduction to Objects and Classes in C#, P...
    - Visual C#.NET, Part 1: Introduction to Progr...
    - C# - An Introduction
    - Hotmail Exposed: Access Hotmail using C#
    - Razor Sharp C#
    - Introduction to Objects and Classes in C#
    - Making Your Code CLS Compliant
    - Programming with MySQL and .NET Technologies
    - Socket Programming in C# - Part II
    - Socket Programming in C# - Part I
    - Creational Patterns in C#
    - Type Conversions
    - Creating Custom Delegates and Events in C#
    - Inheritance and Polymorphism
    - Understanding Properties in C#







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 8 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek