In the first case, GetAmountResponse is in the namespace http://ws.dsi.otn.com/dab , while etat and montant are in the empty namespace by default.
In the new desired post, GetAmountResponse , etat and montant are in the http://ws.dsi.otn.com/dab namespace.
Namespaces can be managed from the namespaces of your classes. Use the same namespace in all, and you will have them in the same namespace, leave the default classes and the default empty namespace.
For example, if you have something like this in your web service:
@WebMethod public @WebResult(name = "getAmountResponse", targetNamespace = "http://ws.dsi.otn.com/dab") AmountResponse getAmount( @WebParam(name = "getAmountRequest", targetNamespace = "http://ws.dsi.otn.com/dab") AmountRequest request) { AmountResponse response = new AmountResponse(); response.setEtat(0); response.setMontant(500.0); return response; }
with the response class as follows:
@XmlRootElement public class AmountResponse { private int etat; private double montant;
You will receive the first type of soap message.
But if you change the response class to look like this:
@XmlRootElement(namespace = "http://ws.dsi.otn.com/dab") @XmlAccessorType(XmlAccessType.NONE) public class AmountResponse { @XmlElement(namespace = "http://ws.dsi.otn.com/dab") private int etat; @XmlElement(namespace = "http://ws.dsi.otn.com/dab") private double montant;
you bring all the tags in one namespace and get something equivalent to the new type of message you want. I said the equivalent, because I donβt think you will get exactly this:
<GetAmountResponse xmlns="http://ws.dsi.otn.com/dab"> <etat>0</etat> <montant>500.0</montant> </GetAmountResponse>
Most likely, you will get something like this:
<ns2:getAmountResponse xmlns:ns2="http://ws.dsi.otn.com/dab"> <ns2:etat>0</ns2:etat> <ns2:montant>500.0</ns2:montant> </ns2:getAmountResponse>
This is the same "XML value" for both messages, although they do not look the same.
If you absolutely want this to look like this, I think you will have to go βlowβ and use something like a SOAP handler to intercept the response and change it . But keep in mind that it will not be a trivial task to change the message before it goes to the wire.