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
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.
@Martin Klinke
"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)."
As far as I know the performance issue makes difference during serialization-deserialization in other words marshalling-demarshalling process.I am not sure both these terms are same btw In distributed programming,I am not talking about the process which happens in the same JVM,it's about how you copy data.It is either pass by value or pass by reference.Binary format corresponds to pass by value which means copying an object to remote server in binaries.If you have any doubt until now I d like to hear
what's the difference between sending in binary format and textual/xml content in terms of marshalling-demarshalling or serialization-deserialization?
I am just guessin.It does not depend on what kind of data you send.Whatever data type you send it'll be part of marshalling-demarshalling process and at the end will be sent in binaries right?
cheers Hakki
What about Spring Remoting. It combines REST-like HTTP protocol with binary format of RMI. Works perfectly for me.
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
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.
RMI may be the better direction if you need to maintain complex state.