Developer Resources’s Weblog

June 8, 2008

C# Web Services

Filed under: C#.NET, Web Services — Tags: , , — developerresources @ 11:52 am

This Post illustrates how to write a simple C# Soap Client.

For more information about C# I recommend the following book: Programming .NET Web Services.

C# is not an interpreted language like Perl or Python, so before you can consume a web service you must first generate a stub class. In Visual Studio click Tools->Visual Studio Command Window

In the command window type wsdl this will generate a c# stub file your current directory. Copy this file into your c# project.

For an example lets use the following web service: http://www.webservicex.net/stockquote.asmx?wsdl.

This will create a stub file called StockQuote.cs.

To call this service you just need the following code



using System;
using System.Collections.Generic;
using System.Text;
namespace TestWebService
{
  class Program
  {
    static void Main(string[] args)
    {
      StockQuote stockQuote = new StockQuote();
      Console.WriteLine(stockQuote.GetQuote("nvda").);
    }
  }
}

Thats it! Make sure to include the System.web.Services references by right click on your project name and selected Add References.

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.