views:

5656

answers:

6

Hi,

I'm new to both Web Services and RMI and I wonder which is the better way to do remoting between different web applications, when these applications are all written in Java, that is when different programming languages don't matter (which would be the advantage of WS).

While on the one hand I would guess that there's a performance overhead when using web services (does anyone have some numbers to prove that?), on the other hand it seems to me that web services are much more loosely coupled and can be used to implement a more service-oriented architecture (SOA) (which isn't possible with RMI, right?).

Although this is quite a general question, what's your opinion?

Thanks

A: 

My experience with RMI and Web Services mirrors your guesses above. In general, RMI's performance far exceeds web services, but the interface specification is explicitly stated for Web Services.

Note that neither of these protocols requires that the applications on both sides be Java. I would tend to use Web Services when I had one or more external partners who were implementing the interface, but RMI if I was in control of both ends of the connection.

Steve Moyer
+3  A: 

Whether you use Web Services or a more "native" approach depends on the environment as well. If you have to pass through a proxy or some corporate firewall(s), Web Services are more likely to work since they are relying on HTTP only. RMI requires you to open another port for your application which may be difficult (not technically, though) in some environments...

If you know that this issue is not a problem, you should consider using RMI. SOA does not depend on technology so much as on good service design. If you have an EJB container, you can call session beans via RMI and additionally expose them as web services, if you really need to, by the way.

The performance depends on the data that you are planning to exchange. If you want to send complex object nets from one application to another, it's probably faster with RMI, since it's transfered in a binary format (usually). If you have some kind of textual/XML content anyway, web services may be equivalent or even faster, since then you would not need to convert anything at all (for communication).

HTH,
Martin

Martin Klinke
+1  A: 

The web services do allow a loosely coupled architecture. With RMI, you have to make sure that the objects stay in sync in all applications, which means that you always have to deploy both of them at the same time even if only one of them is changed (not necessarily, but it is required quite often because of serial UUIDs and whatnot)

Also it is not very scalable, which might be an issue if you want to have load balancers.

In my mind RMI works best for smaller applications, that are not internet-related. I've used it to have a java application that handles electronic communications

Mario Ortegón
A: 

RMI may be the better direction if you need to maintain complex state.

sammyo
A: 

What about Spring Remoting. It combines REST-like HTTP protocol with binary format of RMI. Works perfectly for me.

A: 

For Spring Remoting (I guessed you mean HTTP Invoker), both side should use Spring, if it is the case it can be discussed.

For a Java to Java application RMI is a good solutionö, JAX-RPC or JAX-WS for Java-to-Java communication should be avoided if the clients are not under your control or might move to another platform.