C#
  Home arrow C# arrow Page 2 - 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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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 / 9
    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


    (Page 2 of 4 )

    If you don't have the full .NET Beta 1 Visual Sudio release, that's OK - you can build this stuff in Notepad and compile and run it just fine, as long as you've downloaded and installed the .NET Framework SDK.

    I prefer the Visual Studio IDE for the Intellisense and all the cool access to servers, services, databases, and even Webservices (wherever in the world they may reside) which all get "wired up live" right into your IDE and can be brought in to one central location at your fingertips. But sometimes it's nice to just whip out NotePad or EditPlus and start codin' (kind of like when your Commodore 64 used to come up with the blue screen saying "38632 BASIC BYTES FREE"-- man those were the days...).

    First we need to start a new .asmx file because that's what tells the CLR (Common Language Runtime) that this is a Webservice. We start out by declaring our PageLanguage and starting class name, along with the CLR references that we'll need for the webservice:
    <%@ WebService Language="C#" class="StockQuote" %>
    using System;
    using System.Web.Services ;
    using System.Net;
    using System.IO;
    using System.Text;

    Next we declare our public class "StockQuote" as a webservice, with the [WebMethod] directive:

    public class StockQuote : WebService
    {
    [WebMethod]

    Then we declare our public function and set up some required variables, along with the beginning of our try-catch block:

    public string GetQuote(string symbol)
    {
    string result = null;
    try
    {
    //URL to Yahoo spreadsheet format stock quote server...
    string serverURL = @"http://quote.yahoo.com/d/quotes.csv?s="+symbol+"&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";
    char[] delim = {' '};
    char[] delim2 = {','};
    string[] symbols = symbol.Split(delim);
    string sTemp = @"";
    string sContentTemp = @"";
    string sContentNew = @"";
    string strChar = "";

    We then create a HttpWebRequest object for the stock URL:

    HttpWebRequest webreq = (HttpWebRequest)WebRequestFactory.Create(serverURL);

    -- and Retrieve HttpWebResponse object from the stock URL using the StreamReader object:

    HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
    StreamReader strm = new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);

    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-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway