1

我是 CXF 和 JAXB 的新手。我正在尝试使用 CXF 上的 Eclipse 从 Java 类(自下而上的方法)生成 WSDL。

作为研究员创建了界面。

@WebService(name = "EBMData", targetNamespace = "http://business.kp.org/")
public interface EBMData {

    @WebMethod
    public @WebResult OPStatusDetails addEBMFields(InputFields fields);

    @WebMethod
    public @WebResult OPStatusDetails addOLIs(InputOLIs olis);


}

请求 XML JAXB 类如下

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="InputFields")
@XmlRootElement(name="InputFields")
public class InputFields {

    @XmlElement(name="FieldName", required=true)
    String fieldName;

    @XmlElement(name="Oli", required=true)
    List<String> olis;

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public List<String> getOlis() {
        return olis;
    }

    public void setOlis(List<String> olis) {
        this.olis = olis;
    }



}

响应 XML JAXB 类如下

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="OPStatusDetails")
@XmlRootElement
public class OPStatusDetails {

    @XmlElement(name="returnMessage", required=true)
    String returnMessage;

    public String getReturnCode() {
        return returnMessage;
    }

    public void setReturnCode(String returnMessage) {
        this.returnMessage = returnMessage;
    }



}

创建上述类后,使用 new-> web Service 并使用自下而上的方法选项。并生成 WSDL。

生成 WSDL 后,可能会注意到创建了一个新包。带有文件 AddEBMFields.java

@XmlRootElement(name = "addEBMFields", namespace = "http://business.kp.org/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addEBMFields", namespace = "http://business.kp.org/")

public class AddEBMFields {

    @XmlElement(name = "arg0")
    private org.kp.business.xmls.InputFields arg0;

    public org.kp.business.xmls.InputFields getArg0() {
        return this.arg0;
    }

    public void setArg0(org.kp.business.xmls.InputFields newArg0)  {
        this.arg0 = newArg0;
    }

}

和 AddEBMFieldsResponse.java

@XmlRootElement(name = "addEBMFieldsResponse", namespace = "http://business.kp.org/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addEBMFieldsResponse", namespace = "http://business.kp.org/")

public class AddEBMFieldsResponse {

    @XmlElement(name = "return")
    private org.kp.business.xmls.OPStatusDetails _return;

    public org.kp.business.xmls.OPStatusDetails getReturn() {
        return this._return;
    }

    public void setReturn(org.kp.business.xmls.OPStatusDetails new_return)  {
        this._return = new_return;
    }

}

由于这些文件,我的请求 XML 生成如下,而不是 arg0 字段,它需要从 InputFields.java 中引用。你能帮忙吗?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bus="http://business.kp.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <bus:addEBMFields>
         <!--Optional:-->
         <arg0>
            <FieldName>?</FieldName>
            <!--1 or more repetitions:-->
            <Oli>?</Oli>
            <Oli>?</Oli>
            <Oli>?</Oli>
         </arg0>
      </bus:addEBMFields>
   </soapenv:Body>
</soapenv:Envelope>

我也想

o know how my JAXB class should for the following soap request xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bus="http://business.kp.org/">
       <soapenv:Header/>
       <soapenv:Body>
          <bus:addEBMFields>
             <!--Optional:-->
            <FieldName>?</FieldName>
            <!--1 or more repetitions:-->
            <Oli>?</Oli>
            <Oli>?</Oli>
            <Oli>?</Oli>
          </bus:addEBMFields>
       </soapenv:Body>
    </soapenv:Envelope>
4

1 回答 1

1

添加:

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

到 EBMData 接口。默认情况下,它将为操作创建包装器。指定 BARE 模式将直接使用类型。

于 2013-05-10T14:11:11.283 回答