Mono WebServices

Posted on Sunday, November 14, 2004 in Uncategorized

Whilst converting fellow CLUG’er Mark to Mono (on Windows no less!) last night, I decided to revisit my promise to publish my ‘Hello’ web service. Whilst chatting to him, I re-coded it as a Mono ASP.NET Web Service which can be seen here.

Writing the Web Service

My web service ‘page’ consists of one line:

 <%@ WebService Language="c#" Class="Schwuk.HelloWorld" %>

Whilst my web service ‘logic’ (code behind as usual) consists of:

 using System;
 using System.Web.Services;

 namespace Schwuk
 {

 [WebService(Namespace="http://schwuk.com",Description="Very simple test webservice")]
         public class HelloWorld : System.Web.Services.WebService
         {
                 [WebMethod(Description="Says Hello")]
                 public string SayHello(string Name)
                 {
                         return String.Format("Hello {0}", Name);
                 }
         }
 }

This is compiled with:

 $ mcs -t:library -r:System.Web.Services -out:bin/HelloWorld.dll HelloWorld.cs

Consuming the Web Service

The easiest way to consume the web service is to use it’s WSDL file (you can find mine here) to create a proxy client.

You’ve got two ways of doing this from Mono/.NET:

Use the proxy client generated by the web service itself Generate a proxy client using the WSDL tool

Since the first option is pretty self explanatory, I’ll quickly demonstrate the second option.

 $ wsdl -n:Schwuk http://schwuk.com/wip/HelloWorld.asmx?wsdl

This generates a HelloWorld.cs file that can be included in your project. I specify a namespace with the -n: option, but that’s optional.

Demonstrating the Web Service

I re-implemented my original HelloWorld app as HelloWorldClient using this new web service. You can grab the MonoDevelop project here or the client itself in the following forms:

Here it is running on Linux:

and here running on XP (courtesy of Mark):

This is the same executable – no recompilation was required.

Related posts:

Mono WebServices - Part 2 On a roll here… I’ve converted my Mono -> MySQL... Mono re-enabled I finally got around to re-enabling Mono on this server... Better late than never! The title applies to more than one topic… .NET Rocks!... Mono 1.1.9 OK so I’m a bit late, but Mono 1.1.9 has... Mono eye for the Java guy Balazs Fejes has posted an article on his experiments in...

Related posts brought to you by Yet Another Related Posts Plugin.

I cant get your example to work with xsp.<br />
<br />
I have copied your sourcecode and compiled it successfully using the command you specified.<br />
<br />
I then started xsp specifying the root folder where I have my asmx file and where I put the bin/HelloWorld.dll file.<br />
<br />
When I try to view the page in my browser I get the following error:<br />
System.TypeLoadException: Cannot load type &#8216;Schwuk.HelloWorld&#8217;<br />
<br />
Im quite new in the world of Mono and any help would be greatly appriciated.

hello,<br />
I am not very good with English, I describe my problem.<br />
I want to carry out a web service with C# that consents to a db mysql, but when including the class byteFx. it dates. mysqlclient comes out me an error in the compilation, something with respect to that she/he is not the place of the class, next I place the inclusion code using bytefx.data.mysqlclient.<br />
this it is my problem, also like I can consume the web service from an application windows made in C #you remember that the web service this in linux running low xsp <br />
thank you for your help


Mobilized by Mowser Mowser
Mobilytics