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:
- 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.
About this entry
You’re currently reading “ Mono WebServices ,” an entry on schwuk.com
- Published:
- 11.14.04 / 5am
- Category:
- Uncategorized
Comments are closed
Comments are currently closed on this entry.