0

我有一个定义远程设备的 SOAP 消息的 XSD。我想使用这个 XSD 并从中生成 Java 源代码来创建这些消息。XSD 中的一条消息的示例如下:

<xs:element name="get-ethernet-stats">
    <xs:annotation>
        <xs:documentation>Ethernet stats information</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element name="mode" type="response-mode"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="get-ethernet-stats-resp">
    <xs:complexType>
        <xs:annotation>
            <xs:documentation>Ethernet Stats</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element ref="status"/>
            <xs:element name="result" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="rx" type="xs:int"/>
                        <xs:element name="tx" type="xs:int"/>
                        <xs:element name="drops" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

关于如何做到这一点的任何建议?我查看了 JAXB,但没有原始源文件,当我运行“xjc file.xsd”来获取源文件时,这里是输出的一部分:

parsing a schema...
compiling a schema...
[ERROR] A class/interface with the same name "file.MemosReceipt" is already in use. Use a class customization to resolve this conflict.
  line 7669 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Relevant to above error) another "MemosReceipt" is generated from here.
  line 8242 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] A class/interface with the same name "file.InstructionsReceipt" is already in use. Use a class customization to resolve this conflict.
  line 7720 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Relevant to above error) another "InstructionsReceipt" is generated from here.
  line 8341 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 7686 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Related to above error) This is the other declaration.   
  line 8267 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 8626 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

[ERROR] (Related to above error) This is the other declaration.   
  line 6114 of file:/Users/rwb7041/Documents/file/xsd/file.xsd.xsd

Failed to produce code.
4

1 回答 1

0

我建议你看看jaxws-rt-2.1.4.jar。这允许两种方式提供要在 SOAP 消息中发送的 XML:
(1) 仅提供正文内容;代码负责根据检索到的 wsdl 添加 Envelope/Header/Body 和命名空间
(2) 提供完整的 Envelope 和命名空间

那时不需要代码生成。

参见例如 jaxws-guide.html

于 2012-04-07T16:45:38.990 回答