views:

509

answers:

3

Having been primarily a .NET guy up until starting a new job recently; I've only done Web-Service development and consumption in C#/.Net. However I'm embarking on the journey to learn the ins and outs of doing it on the J2EE platform, and I'm curious what the major differences are in this specific type of development.

Note: I have familiarity with the Java Language at the console/simple interface level, but not much experience with "How to put together a functional Web Service Architecture" using it.

Update: Great answers so far, I just wanted to add however that in the simple web-service class structure they don't seem to display too many differences; but how about from the perspective of putting it all together with DB logic and actually hosting it - getting the service running and working/how its interacted with.

+4  A: 

I never tried before web services but recently. And I was amazed with how simple it is in Java with JAX-WS.

Here is a web service

@WebService
class BusinessProcess implements IBusinessProcess
{
   public HelloWorldObject helloWorld()
   {
      return new HelloWorldObject("Earth");
   }
}

And that's it.
If you need an extra logic and level like DB Entities it is added as easy as I could only imagine with EJB3.

As far as I just saw the C# way of defining the WebService there is no big difference at all.

    [WebService(... )]
    public class BusinessProcess : System.Web.Services.WebService
    {
        [WebMethod]
        public HelloWorldObject helloWorld()
        {
            return new HelloWorldObject("Earth");
        }
    }

I believe there is a difference in further logic though.

Mykola Golubyev
+3  A: 

I would suggest taking the Apache CXF framework for a spin. I selected it for a major project here at work and it works great! What advantages does this give you over EJB3? Hmmm... I couldn't say except that I've used CXF, while EJB3 has never been in my kitchen (obscure Cheers reference).

With CXF the code isn't much more than a couple annotations here and there. It uses standard JAXB annotations for marshalling objects. Via configuration it is also possible to place interceptors before and after the web services calls if you want to do logging, etc.

@WebService
public interface UserService {
    public Collection<User> getUsers(@WebParam(name = "systemID") Long sysID);
}

Note that the @WebParam annotation is optional, but it looks nicer in the WSDL than stuff like arg0. Yes, there might be a little bit of XML configuration to go along with that:

<!-- the #userService is a reference to a Spring bean defined elsewhere --> 
<jaxws:endpoint id="userWS" implementor="#userService"
 implementorClass="com.blah.blah.blah.UserServiceImpl"
 address="/UserService" />

As far as consuming web services... Reading the CXF Users Guide will give you a taste for how that's done: http://cwiki.apache.org/CXF20DOC/developing-a-consumer.html

dustmachine
+5  A: 

While there is only one way to do Web Services in .NET using Microsoft Technology, Java Web Services are very fragmented. See this question for example. Most frameworks can do both contract-first (start from the WSDL file) and code-first (start from source code) web services. Each framework has also its way of hosting the Web Service. Axis2 framework for example deploys the web services as AAR files inside the Axis2 Web Application. Other frameworks deploy the web services inside a WAR file (Axis2 can also do).

For people coming from .NET to Java it is always a problem to pick a Web Services framework. IDE integration is also not so good as it is with Visual Studio.

If you are new in J2EE, I recommend to have a look at Spring framework. Spring has a sub-project (Spring-WS) that allows you to create contract-first web services. Integration with DB and application logic is much easier with a dependency injection framework like Spring. Apache CXF also integrates nicely with Spring.

kgiannakakis
Some very good points there - I won't bother answering this now! Good advice.
serg10
I never tried Spring. Is it easier to use Spring for logic then EJB3?
Mykola Golubyev
Most will say that Spring is better than EJB3. It is also more versatile, as it doesn't require an Application Server fully implementing the JEE standard. EJB3 is not bad either, but I recommend to invest your time in Spring.
kgiannakakis