<< EJB 3.0 Will Be Different | Home | Quiz: Default Encoding of Java Source Files >>

I Wrote a Web Service :)

I have never written a Web ServiceTM. Until today, that is.

I've heard all about Axis, WSDL, SOAP, doc/literal, rpc/encoded, JAX-RPC, SAAJ, etc. But the process of setting everything up and actually writing and testing a Web Service in Java just seemed so daunting. And I never got around to try it.

The Beta 1 release of Mono contains a ASP.NET/Web Services host called XSP. So I decided to take it for a spin.

[weiqi@gao] $ cat hello.asmx
<%@ WebService Language="C#" Class="Hello" %>
using System;
using System.Web.Services;
 
public class Hello : WebService {
    [WebMethod()]
    public string SayHello() {
        return "Hello, World!";
    }
}

[weiqi@gao] $ mono /usr/bin/xsp.exe
Listening on port: 8080
Listening on address: 0.0.0.0
Root directory: /home/weiqi/temp/src/webservice
Hit Return to stop the server

The URL http://localhost:8080/hello.asmx gives me the WSDL and client proxy code. I took the client code, added a Main() method, compiled, and run it. It worked as expected.

[weiqi@gao] $ mcs -r:System.Web.Services hello.cs
Compilation succeeded
[weiqi@gao] $ mono hello.exe
Hello, World!


Re: I Wrote a Web Service :)

Give axis a try. Put all the axis jars in the lib of your web app. Create a POJO. Change the extension of your java source file from .java to .jws . Throw the .jws somewhere on your web-app. Thats it.

Re: I Wrote a Web Service :)

I know, I know. I know how to do it. I have watched others set it up and make it work.

It's just that I was never so motivated to want to try it myself. Now that you mentioned it, I did what you said, and everything did work.

I do have to say this: with Axis, there is not the sense of excitement. It's like, Web Services? we can do that. Just understand these 25 concepts, change the file extension and throw it over the fence, whatever.

Mono's XSP, on the other hand, is something new and ground breaking. It's really simple to get your first Web Service going. For a comparable experience in Java, I have to go back all the way to the Applet days. Remember your first Applet? Remember appletviewer? It's kind of like that.

Applet may be out of fasion now. But I believe it is the Applet experience that got Java where it is now.

I just had a similar experience with Mono and XSP. That's about all I have to say about that.

Re: I Wrote a Web Service :)

well, there are some libraries making java web services "ridiculously" easy, like Glue. Also, honestly i prefer binary web services like Hessian. faster.

Re: I Wrote a Web Service :)

I love using Weiqi to learn new things for me and them blog about them. It's almost like a public service.. So.. What is the "[WebMethod()]" declaration on the first line after your declaration of class Hello? On the compile line I see a "-r:System.Web.Services" parameter. Is this analogous to calling out a JAR in a classpath paramater for java?

Re: I Wrote a Web Service :)

Public Services "R" Us!

The "[WebMethod()]" is an attribute that makes the method a Web Service. JDK 1.5 will support something similar through JSR 175. We call them annotations.

The "-r:System.Web.Services" switch tells the C# compiler to link against the System.Web.Services.dll. It's similar to the "-l" switch of gcc. By default the Mono C# compiler only compiles and links against a finite subset of the dll's shipped with it.

Re: I Wrote a Web Service :)

I tried your example on my mono 1.0 configuration. For some reason xsp can't seem to find the System.Web.Services. Here is the exact error that xsp returns when I try and link from my browser.. Parser Error Description: Error parsing a resource required to service this request. Review your source file and modify it to fix this error. Error message: Unknown directive: WebService File name: /home/tgruben/Projects/Mono/hellow.aspx Line: 1 Any Ideas? I can't seem to find any docs on configuring xsp.

Re: I Wrote a Web Service :)

I recently installed mono on my fedora core2 system and have been trying out some sample code that I have run across. I also installed mono on windows but xsp doesnt seem to work on it. Anyway I tried out a simple example with xsp and while looking around for something else to try came across your site. First of all I dont really know what a web service is but your example hello.asmx did work for me displaying the web page and the link to the client proxy code works also. I dont understand the client proxy at this time and couldnt figure out how to add the main method. Can you post the code with the main method added. I am hoping that I will start to understand the client proxy code once I get it to compile and run. Thanks

Add a comment Send a TrackBack