Build a C# Stock Quote WebService Part 1/2
(Page 1 of 4 )
Peter Bromberg of EggheadCafe.com discusses how to build a C# stock ticker using XML Web Services.Spring is almost here, and it's time to create .NET stuff! So, building on my article of last year, "Build a Custom Stock Quote Component", I decided it would be a fun exercise to "stretch my skills" a bit and build a new one, but this time -- to do it in C# as a full-fledged .NET WebService. And, since Microsoft has been nice enough to give away a WebService Behavior HTC that can be "plugged in" to a DHTML web page to act as a webservice consumer, I thought that would be an elegant finishing touch to show an example of building a consumer Web page for my new StockQuote class.
We'll deal with getting the WebService built and running in this installment, and in Part II, we review how to use the WebService DHTML Behavior in a regular client-side .htm page to consume the WebService. (The downloadable code link at the bottom of this article, however, contains ALL the code, 'cause I know how you hate to wait for people's "multiple part' articles!) In Part II, I'll get into some neat client-side stuff, so visit often.
On a side note, If you're in a quandary about DOT NET and you aren't sure whether to stay with VB6 or go to VB7 or start with C#, my advice is -- after a great deal of agonizing study and thought -- conserve all the extra time you can find, DROP EVERYTHING, and get started with C#.
Forget VBScript (its already a dinosaur) as well as VB6 and even Javascript. Microsoft has over a million lines of C# code in the .NET platform - those guys are eating, breathing, sleeping and everything else in C#. And unlike their brethren at Oracle and Sun, they've submitted it to the ECMA for certification.
In sum, C# is an elegant, simple, and powerful programming language that you're almost certain to see on other platforms while the Java guys who are still too busy bashing the guys in Redmond to see what's comin' at-em on the turnpike at 100 miles an hour will likely be wondering what happened.
In this article, we're going to walk through the Webservice C# code first, and then we'll take a look at the DHTML page and how the WebService Behavior can be used to easily wire up the page to act as a webservice consumer.
While this is a pretty simple class with only one method, "GetQuote" it still demonstrates some important techniques- handling and parsing multiple stock symbols as input parameters, utilizing the WebRequestFactory class, as well as the StreamReader and StringBuilder .NET classes to parse and clean up the response stream and process the return values.
Finally, we'll build a valid XML return document that the WebService returns to the calling client, as well some simple error -handling code.
Next: Building the Ticker >>
More C# Articles
More By Peter Bromberg