Click here to Skip to main content
Click here to Skip to main content

Tagged as

Developing a GTK# Application that Retrieves Detailed Stock Information using MonoDevelop and Web Services

, 18 Oct 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Web Services consumption using MonoDevelop and GTK#
Output.PNG

Introduction

This article introduces GTK# development with MonoDevelop for consuming simple web services. The web service we are going to use is the Stock Ticker service available at http://www.webservicex.net/stockquote.asmx?wsdl.

Background

This project is developed using MonoDevelop and GTK# 2.0. I have developed and tested this application in KDE 3.5 and GNOME with OpenSUSE 11.

Creating a Web Reference

First, we need to create a Web Reference to the Stock ticker service in the form of a DLL file so that we can consume it. Here are the steps for the same.

  1. Convert the WSDL of the Web Service in C# Code using wsdl tool.
  2. Generate a Library file using the generated .cs file.

Open your terminal and type the following commands:

$ wsdl www.webservicex.net/stockquote.asmx?wsdl
$ mcs /target:library StockQuote.cs    -r System.Web.Services

A DLL file with the name StockQuote.dll will be created. Though we can do this using the MonoDevelop IDE, I prefer this technique because we could store all web references in one special folder and reference them as required in projects.

Create a new Solution in MonoDevelop. Add a project of the type GTK# 2.0.

1_New_Solution.JPG

Then, the project will create a GTK# form with the name MainWindow.cs. You can open this in Designer mode which shows up a WYSIWYG editor. One major feature of GTK# for design is that it asks you to first define a Container before you get to add any Widgets.

I have used a table as my container to design the form as shown below:

1_Form_Design.JPG

The StockQuote web service returns the result in an XML format. So we need to extract information from it. You can see the format here. Just lookup a company, say MSFT and see the format of result. Therefore, we need to add two References, one is for System.Xml and the other is for the StockQuote.dll we generated earlier.

References can be added easily by Right clicking the References folder in Solution window and selecting Edit References... This will open a dialog box as shown below:

1_Add_Ref_XML.JPG

Next, we add the reference to StockQuote.dll by selecting the .NET Assembly Tab.

Add_.NET_Assembly.JPG

In GTK#, a Widget is associated with Signals. Signals associated with a widget can be seen in the Properties window when we select in the designer. We can double click on the Signal to generate event handler. Next, we add signal handler to the Button "Get latest stock information" and write the following code:

protected virtual void OnButton1Clicked (object sender, System.EventArgs e)
{
    String quoteSymbol="MSFT";
    if(radOwnSym.Active){
        if(txtOwn.Text=="")
        return;
        quoteSymbol=txtOwn.Text;
    } 
    if(radPreDef.Active){
        quoteSymbol=cmbTemplate.ActiveText;
    }
    StockQuote quote = new StockQuote();
    string toParse=(quote.GetQuote(quoteSymbol)); 
    XmlDocument doc=new XmlDocument();
    doc.LoadXml(toParse);
    Console.WriteLine(toParse);
    lblLast.Text=doc.FirstChild.FirstChild.ChildNodes[1].InnerXml;
    lblStockSymbol.Text=doc.FirstChild.FirstChild.ChildNodes[0].InnerXml;
}

We can then build the project by pressing F8. The project can be run by pressing the F5 key.

Points of Interest

The code for the designer refused to show up the IDs of the widgets that I dragged and dropped. I got toppled in the first place. It actually shows the widget IDs when you compile the project after dropping the widgets.

History

  • v0.1b Retrieving detailed stock information of a given stock symbol

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shyam Bharath
Software Developer Droid Labs
India India
Shyam Bharath just finished his bachelor of technology in Computer science and Engineering from Vellore Institute of Technology. He is passionate about application development. He loves coding in C#, Python and more recently Mono.
 
Right now he is working in J2EE technologies in a private firm in India. In his spare time, he reads spiritual books.
 
Please feel free to visit my projects
Exam-O-Matic - Online exam conduction tool in ASP.NET
 
Visit me on my blog at
Crystal Avatar Blog

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 19 Oct 2008
Article Copyright 2008 by Shyam Bharath
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid