Home arrow C# arrow Page 3 - Build a C# Stock Quote WebService Part 1/2
C#

Build a C# Stock Quote WebService Part 1/2


Peter Bromberg of EggheadCafe.com discusses how to build a C# stock ticker using XML Web Services.

Author Info:
By: Peter Bromberg
Rating: 5 stars5 stars5 stars5 stars5 stars / 36
January 06, 2003
TABLE OF CONTENTS:
  1. · Build a C# Stock Quote WebService Part 1/2
  2. · Building the Ticker
  3. · Building the Ticker (cont'd)
  4. · Conclusion

print this article
SEARCH DEVARTICLES

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.
blog comments powered by Disqus
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#

Watch our Tech Videos  
Dev Articles Forums  
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us  
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us  
Site Map  
Privacy Policy  
Support  

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials