Cuándo usar la API SOAP de Java

edited the question to improve clarity.

I am trying to learn SOAP based Java Web services. I created a simple web service using the @WebService annotation. I published it in my local machine and I consumed the service in my local machine. I found out that the WSDL file is auto generated and the SOAP messages are 'under the hood'. I was able to track the SOAP messages only through TCP/IP monitor.

I later found that Java SOAP API give the option to create SOAP messages ourselves and transmit them using classes/interfaces like MessageFactory and SOAPMessage.

My question is, if WSDL and SOAP messages are generated and handled automatically, why would we need SOAP handlers to manually create and send SOAP messages using the Java SOAP API?

preguntado el 28 de agosto de 12 a las 11:08

2 Respuestas

My question is, if WSDL and SOAP messages are generated and handled automatically, why would we need SOAP handlers to manually create and send SOAP messages using the Java SOAP API?

Because you might want to have more control over SOAP communication, building a SOAP message etc. When mentioning MessageFactory and SOAPMessage, you're actually referring to SAAJ. Compared to JAX-WS, SAAJ is operating at lower level with all pros and cons that this approach brings. From Java rocking:

JAX-WS versus SAAJ

From a practical standpoint, using SAAJ means that you don’t use tools such as 'wsimport' or 'wsdl2java'. Those are for use with JAX-WS, and are the means by which a client can generate domain objects and operate almost as if they were not using web services at all. With SAAJ, you have no domain view of a service. You are really working with the plumbing. Development with JAX-WS can be much quicker and easier, and generally does not cause you any loss in control. But JAX-WS is a convenience layer, and it can be comforting to know that if you wield some command of SAAJ, you’ll be ready to do anything that a WSDL interface requires of you.

Personally, I would always go with JAX-WS.

Respondido 28 ago 12, 12:08

You don need to use Java SOAP API explicitly when you use JAX-WS. But you choose to write SOAP messaging applications directly, then these APIs come into picture.

An hypothetical example would be that you want more control over the SOAP message parsing. You do not want to process the entire XML but a part of it using xpath.

Respondido 28 ago 12, 12:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.