简体   繁体   中英

generating the right SOAP XML structure from a JAXB annotated class

Generated from the ProcessRequestBean class listed at the end,
This is what I get:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cel="http://www.myweb.com">
  <soapenv:Header/>
  <soapenv:Body>
     <cel:processRequestOp>
        <processReq>
           <!--Optional:-->
           <serviceID> 1 </serviceID>
           <!--Zero or more repetitions:-->
           <parameter>
                <!--Optional:-->
                <name> myname </name>
                <!--Optional:-->
                <value> myvalue </value>
           </parameter>
        </processReq>
    </cel:processRequestOp>
  </soapenv:Body>
</soapenv:Envelope>  

But this is what I want:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cel="http://www.myweb.com">
    <soapenv:Header/>
    <soapenv:Body>
        <cel:processRequestOp>
             <!--Optional:-->
             <serviceID>1</serviceID>
             <!--Zero or more repetitions:-->
             <parameter>
                <!--Optional:-->
                <name> myname </name>
                <!--Optional:-->
                <value> myvalue </value>
            </parameter>
        </cel:processRequestOp>
      </soapenv:Body>
   </soapenv:Envelope>

Note, the exta parent (processReq) element that is eliminated from this structure.

My SEI looks like this:

@WebService(name="QueryThirdParty", targetNamespace = "http://www.myweb.com")
@SOAPBinding(style = Style.RPC)
public interface QuerySEI {

public static final String targetNS = "http://www.myweb.com";

@WebMethod(operationName = "processRequestOp", action = "get_them")
@RequestWrapper(className =  "biz.webservice.query3rdpartyaccount.ProcessRequestBean", localName = "localName", partName = "partName")
@ResponseWrapper(className = "biz.webservice.query3rdpartyaccount.ProcessResponseBean")
@WebResult(partName = "processResp", name = "processRequestResponse")
public ProcessResponseBean getAccountNumbers(@WebParam(partName = "processReq", name = "ProcessRequestBean", mode = Mode.IN) ProcessRequestBean request);

}   

and ProcessRequestBean class looks like this:

@XmlRootElement(name = "processRequest") //the name of the XML root element 
@XmlType(propOrder = {"serviceID", "parameter"})
public class ProcessRequestBean {

private String serviceID;

private List<RequestParameterElement> parameter;

public ProcessRequestBean(String serviceID, List<RequestParameterElement> parameter) {
    this.serviceID = serviceID;
    this.parameter = parameter;
}

public ProcessRequestBean() {
}

@XmlElement(name = "serviceId")//xml name of this property
public String getServiceID() {
    return serviceID;
}

public void setServiceID(String serviceID) {
    this.serviceID = serviceID;
}    

@XmlElement(name = "parameter")
public List<RequestParameterElement> getParameter() {
    return parameter;
}

public void setParameter(List<RequestParameterElement> parameter) {
    this.parameter = parameter;
}
}

all help is appreciated

Please try following changes in ur SEI and ProcessRequestBean class,

SEI

@WebResult(partName = "processResp", name = "processRequestResponse")
public ProcessResponseBean getAccountNumbers(ProcessRequestBean request);

}   

ProcessRequestBean class

get rid of @XmlRootElement(name = "processRequest") annotation..

      @XmlAccessorType(XmlAccessType.FIELD)    
      @XmlType(propOrder = {"serviceID", "parameter"})
public class ProcessRequestBean {

private String serviceID;

private List<RequestParameterElement> parameter;

public ProcessRequestBean(String serviceID, List<RequestParameterElement> parameter) {

......
......
......

Let me know if it doesn't resolve ur prblm.

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