I have a web service (JAX-WS) that outputs

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body wsu:Id="body" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <ns3:requestDataResponse xmlns:ns2="http://uslugi.ru/rev" xmlns:ns3="http://services" xmlns:ns4="http://services"> <ResponseData> <message> <status>Normul</status> </message> <messageData> <appData> <response> <fio> <firstName>ima</firstName> </fio> </response> </appData> </messageData> </ResponseData> </ns3:requestDataResponse> </soapenv:Body> </soapenv:Envelope> 

and I would like it to output without requestDataResponse, i.e. Body was only ResponseData.

ResponseData

 @XmlRootElement(name = "ResponseData", namespace = "http://uslugi.ru/rev") @XmlAccessorType(XmlAccessType.NONE) public class ResponseData { @XmlElement private Message message; @XmlElement private MessageData messageData; public Message getMessage() { return message; } public void setMessage(Message message) { this.message = message; } public MessageData getMessageData() { return messageData; } public void setMessageData(MessageData messageData) { this.messageData = messageData; } } 

service and method

 @WebService(name = "IRequest", targetNamespace = "http://services") public interface IRequest { @WebMethod @WebResult(name = "ResponseData") public ResponseData requestData( @WebParam(name = "Header", header = true) Header header, @WebParam(name = "Message") Message message, @WebParam(name = "MessageData") MessageData messageData); } 

    2 answers 2

    The only way I found is to clean the body in the handler, and then fill it with my own data. It was not possible to overcome standard namespaces, someone wrote about packege-info and @XmlSchema, but I didn’t try this

      Libraries for web services usually have a tool for generating a skeleton of a service from a WSDL description. Build the required WSDL for your service and use this tool.

      If it does not work out - change the library used.

      • I describe the entire skeleton through classes, saying what will be at the input and what is at the output, only at the output everything described falls into an element whose name corresponds to the name of the method + "Response" (for example, requestDataResponse). Also, all namespaces are knocked into a mess, even if they are stamped, then the prefixes have standard names (ns1, ns2, ...), which you have to delete in the handler and prescribe again so that they are called as I need. - Alex Mandelbrot
      • one
        You solve a strange problem by a strange method. If you need to quickly make a web service - if you don’t care, how is it going to be in XML? And if you need to get XML with a specific scheme, then you need to create a WSDL and from it already generate a service. - Pavel Mayorov
      • It seems I understood your thought. I will definitely try, thank you - Alex Mandelbrot