简体   繁体   中英

How Java objects are passed in SOAP web services

SOAP Web Services can be platform and language independent. And can accept parameters from client and can send response back to the client. Ex - I can pass a city as string parameter and get back weather information as response.
But what if I have to pass a java object - say person object and get back his credit score. (say person object has atributes like name, age, ssn, address etc) (and address itself can be another java object with attributes like - street, city, zip etc)

Can the SOAP service accept the object right away or the person object needs to be passed after extracting all the primitive information and this information needs to be passed to the service as strings or ints only - as (name, age, ssn, street, city, zip)

Can the SOAP service accept the object right away or the person object needs to be passed after extracting all the primitive information and this information needs to be passed to the service as strings or ints only ?

You need to know the below points:

(1) SOAP is a protocol with some predefined specifications/format (with header, body, etc. elements) for data exchange across two different applications (developed with the same or different programming languages).

(2) When you are consuming a SOAP service, you are the SOAP client.

(3) When you have exposed/provided a SOAP service for other users, you are the SOAP service provider.

(4) SOAP services do NOT use the java objects directly as they are. Rather, they will be converted into xml (called marshaling) and then sent/received .

(5) So, when you call a SOAP service provider, your person java object will be marshalled into an xml format and sent to the SOAP service provider.

(6) SOAP service provider will receive the xml and convert into their representation (called unmarshalling) according to their platform ie, it could be Java or .net or any other.

(7) After processing the request, SOAP service provider will prepare the response (Object/something converted to xml) and send it to the caller.

(8) To make the marshaling and unmarshaling easily (ie, conversions between Java to XML and vice-versa), there are several tools available in Java like JAXB , XMLBeans , etc.

PS: I have just mentioned the message format as xml (which is common) for your understanding, but it could be any other format the applications could be agreed with.

You can look here for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM