not logged in  
login | register  

Docs:

Documentation
Web Services
FAQs
Downloads
Contact
References

Up

2.1 Web service clients using the .net framework and c#

The whole .net framework was designed with web services kept in mind, so it is the best option to start with if you're about to start writing web service client programs. The c# language even has several special features to make it more easier to write web services. Initially developed by Microsoft, but also available on other systems in the form of the Mono project (now under the flag of Novell), which is an open source implementation of the runtime environment and the c# compiler. Compiled code is still portable (just like in java), you can run a windows exe on linux without having programs like wine.

To start with .net on Windows, you will need Visual Studio .net, Visual Studio 2003 or Visual Studio 2005. On Linux, you need the Mono package and the Monodevelop development environment.

In Visual Studio

In Visual Studio you can start creating a web service client by creating a so called console application (that's not using windows, but standard input and output). Visual Studio will generate you an empty project with a main class and a static function called Main() which is the main entry point of the program. To add web service client functionality you have to add a web reference by right clicking on the project's name in the Solution Explorer window. You should then enter the URL of the WSDL file and the proxy classes are generated automatically.

For example, enter the url of the search module of Spectrum Services: http://voservices.net/spectrum/ws_v2_5/search.asmx?WSDL, and Visual Studio will automatically generate you a namespace called net.voservices which has a class named search and all the classes that the service use, such as Sed which is the basic class of the spectrum data model.

Now you can start writing a short program which queries all objects in a given area of the sky. For this purpose you have to use the cone search function. The code to retrieve all spectra in 10 arcminutes around (ra = 180, dec = 1) and list their names looks like this:

<sample code comes here>

Run the program by pressing F5.

In Monodevelop

In Monodevelop...

From command-line

Command-line tools in .net and Mono are very similar. From command-line creating a web service client starts with running WSDL.EXE which generates the proxy code according to the web service's self description file. You should pass the url of the WSDL file to the WSDL.EXE the following way:

wsdl -out search.cs http://voservices.net/spectrum/ws_v2_5/search.asmx?WSDL  

It will generate you a .cs file search.cs containing all the classes you need to access web services. Now open an editor, such like emacs or notepad and copy the following c# code:

<code comes here>

Save it as specclient.cs. To build your program use either csc (on Windows) or mcs (on Mono) which are c# compilers.

csc -out:specclient.exe search.cs specclient.cs

or on Mono

msc -out:specclient.exe -r:/usr/local/lib/mono/1.0/System.Web.Services.dll search.cs specclient.cs

Note, that path to the mono library assemblies may vary depending on your mono install.

To run the program on Windows, simply type specclient, with mono you should run mono specclient.exe.