Mono WebServices
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:
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:
Related posts brought to you by Yet Another Related Posts Plugin.
Recent comments
This theme was designed by Chris Wallace and is licensed under the GNU General Public License.
Check out his cool WordPress Themes. Released by Six Revisions in the year of the rat.
look good
14 Nov 2004 5:17 am
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 ‘Schwuk.HelloWorld’<br />
<br />
Im quite new in the world of Mono and any help would be greatly appriciated.
14 Nov 2004 5:17 am
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