wsdl2java生成ArrayOf <type>而不是Type

时间:2018-02-23 08:28:13

标签: java android wsdl wsdl2java

我使用cfx wsdl2java生成服务器(java文件)。我遇到过一个java类的麻烦。这个java类是complexType,看起来像:

编辑#1:被@ matejko219吸食

<xsd:complexType name="TService">
    <xsd:sequence>
        <xsd:element name="id"
            type="xsd:int" />
        <xsd:element name="st"
            type="xsd:int" />
        <xsd:element name="loc"
            type="tns:TLoc" />
        <xsd:element minOccurs="0" name="str"
            type="xsd:string" />
        <xsd:element name="ti"
            type="xsd:int" />
        <xsd:element name="nump"
            type="xsd:int" />
        <xsd:element name="prc"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="dcrt"
            type="xsd:dateTime" />
        <xsd:element minOccurs="0" name="dini"
            type="xsd:dateTime" />
        <xsd:element minOccurs="0" name="dend"
            type="xsd:dateTime" />
        <xsd:element name="ct"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="ins"
            type="tns:TServiceInspections" />
        <xsd:element name="id"
            type="xsd:int" />
        <xsd:element name="st"
            type="xsd:int" />
        <xsd:element name="loc"
            type="tns:TLoc" />
        <xsd:element minOccurs="0" name="str"
            type="xsd:string" />
        <xsd:element name="ti"
            type="xsd:int" />
        <xsd:element name="nump"
            type="xsd:int" />
        <xsd:element name="prc"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="dcrt"
            type="xsd:dateTime" />
        <xsd:element minOccurs="0" name="dini"
            type="xsd:dateTime" />
        <xsd:element minOccurs="0" name="dend"
            type="xsd:dateTime" />
        <xsd:element name="ct"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="ins"
            type="tns:TServiceInspections" />
        <xsd:element name="area"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="desc"
            type="xsd:string" />
        <xsd:element minOccurs="0" name="tsins"
            type="tns:TInspectionServices" />
        <xsd:element name="nc"
            type="xsd:boolean" />
        <xsd:element name="order"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="tasks"
            type="tns:TServiceTasks"/>
    </xsd:sequence>
</xsd:complexType>

生成的java文件TService.java的变量为ArrayOf 而不仅仅是类型,例如在id中。

 /**
         * Gets array of all "id" elements
         */
    int[] getIdArray();

    /**
     * Gets ith "id" element
     */
    int getIdArray(int i);

    /**
     * Gets (as xml) array of all "id" elements
     */
    org.apache.xmlbeans.XmlInt[] xgetIdArray();

    /**
     * Gets (as xml) ith "id" element
     */
    org.apache.xmlbeans.XmlInt xgetIdArray(int i);

    /**
     * Returns number of "id" element
     */
    int sizeOfIdArray();

    /**
     * Sets array of all "id" element
     */
    void setIdArray(int[] idArray);

    /**
     * Sets ith "id" element
     */
    void setIdArray(int i, int id);

    /**
     * Sets (as xml) array of all "id" element
     */
    void xsetIdArray(org.apache.xmlbeans.XmlInt[] idArray);

    /**
     * Sets (as xml) ith "id" element
     */
    void xsetIdArray(int i, org.apache.xmlbeans.XmlInt id);

    /**
     * Inserts the value as the ith "id" element
     */
    void insertId(int i, int id);

    /**
     * Appends the value as the last "id" element
     */
    void addId(int id);

    /**
     * Inserts and returns a new empty value (as xml) as the ith "id" element
     */
    org.apache.xmlbeans.XmlInt insertNewId(int i);

    /**
     * Appends and returns a new empty value (as xml) as the last "id" element
     */
    org.apache.xmlbeans.XmlInt addNewId();

    /**
     * Removes the ith "id" element
     */
    void removeId(int i);

我的wsdl文件有问题吗?

提前谢谢!!

1 个答案:

答案 0 :(得分:0)

重复了一些属性,因此wsdl2java将其作为数组读取。正确的wsdl是:

<xsd:complexType name="TService">
    <xsd:sequence>
        <xsd:element name="id"
            type="xsd:int" />
        <xsd:element name="st"
            type="xsd:int" />
        <xsd:element name="loc"
            type="tns:TLoc" />
        <xsd:element minOccurs="0" name="str"
            type="xsd:string" />
        <xsd:element name="ti"
            type="xsd:int" />
        <xsd:element name="nump"
            type="xsd:int" />
        <xsd:element name="prc"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="dcrt"
            type="xsd:dateTime" />
        <xsd:element minOccurs="0" name="dini"
            type="xsd:dateTime" />
        <xsd:element minOccurs="0" name="dend"
            type="xsd:dateTime" />
        <xsd:element name="ct"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="ins"
            type="tns:TServiceInspections" />
        <xsd:element name="area"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="desc"
            type="xsd:string" />
        <xsd:element minOccurs="0" name="tsins"
            type="tns:TInspectionServices" />
        <xsd:element name="nc"
            type="xsd:boolean" />
        <xsd:element name="order"
            type="xsd:int" />
        <xsd:element minOccurs="0" name="tasks"
            type="tns:TServiceTasks"/>
    </xsd:sequence>
</xsd:complexType>