views:

1168

answers:

3

How do you compare Java RPC vs Java Web Services. I have a small hands on experience with Web Services. Now I need to know how RPC compares with Web Services. How does RPC work?

Addition : When do we go for either of the options?

A: 

My guess is, that you mean RMI with Java RPC. The remote method invocation is very Java specific, and therefore quite easy to handle in native Java programs (Java on both sides). It uses a binary format to transfer data and doesn't run over HTTP, so it is probably faster than the webservice solution.

Webservices on the other hand use (in general) a generic format like XML or JSON which can be requested and read by any other remote application. The overhead is bigger (making a http request and serializing/deserializing the data), but the client using a webservice doesn't care how the webservice generated that data and doesn't rely on a certain programming language as long as it is in a specified format.

So which technology you want to use depends on if there might be clients other than Java ones, that want to use your service.

Daff
+2  A: 

As Daff says, Java RMI itself is really only relevent to Java-to_Java communications. In terms of ease of development these days the degree of coding from the service provider's perspective is pretty similar.

However in addition to performance issues, where the gap between WebServices and RMI is quite variable (for some message sizes there can be negligable difference,) there's another aspect to consider: resilience.

Typically, RMI is easy to set up when one client talks to one server and you don't mind the availability of the client being coupled to that of the single server. Server down, client down, such is life.

In the Web Service case you can quite easily deploy your service to a cluster of servers and, given that you are invoking the Web Service over HTTP, you can easily exploit all the normal network routing and spraying techniques used in larger scale web sites. No special coding needed in the server or the client.

Now, you can get this same level of resilience with RMI, but that requires a slightly better service-provision infrastructure and thats's where the JEE EJB programming model (or frameworks such as Spring) come in to play. EJB uses RMI over IIOP, a protocol that allows for resilient calling to server instances, transparently dealing with server outages. [It does quite a lot more too, such as secutiry and transactions, but then so can Web Services. Interesting but not part of this discussion.]

Bottom line: For production quality service provision I normally start by creating an service object. I happen to use JEE EJB 3, other folks use Spring. You can expose that service object as a Web Service or as RMI/IIOP with some very simple configuration/annotation. It's very little effort to pick either or both. My world happens to major on interop, so I tend to expose Web Services. If you have only Java to consider it may give some performance improvement to use RMI/IIOP but this is not guaranteed, you would need to measure perfromance to be sure.

djna
A: 

If you are looking at RPC vs Document web-services, this question and the answers may be what you are looking for.

http://www.coderanch.com/t/443021/Web-Services-Certification-SCDJWS/certification/Difference-between-RPC-Document-web#1971102

I could explain it, but when someone has a discussion, with code examples, to look at, my response would pale in comparison.

Besides, I am not certain what it is you are asking about, I think terminology may be an issue here.

James Black