6

我有一个 WSDL 文件,它导入了几个 XML 模式,每个模式都有相同的命名空间(我们称之为 A)。我正在尝试使用 JAXB 外部绑定文件来更改为这些模式生成的包名称(比如说 B)。这是一个例子:

我有一个 POM 文件,其中包含从 WSDL 生成代码的配置(使用 cxf-codegen-plugin)。

我的 WSDL:

<definitions ...>
    <types>
         <xsd:schema elementFormDefault="qualified" targetNamespace="C">
             <xsd:import namespace="A" schemaLocation="SCHEMA_REF"/>
             <xsd:import namespace="A" schemaLocation="SCHEMA_REF"/>
             ...
         </xsd:schema>
    </types>
    ...
</definitions>

这是我的实际绑定文件,它根本不起作用,似乎根本没有应用(没有错误消息......)。

<jaxws:bindings wsdlLocation="WSDL_LOCATION" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" jaxb:version="2.0">
    <jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='C']/xs:import[@namespace='A']">.
        <jaxb:schemaBindings>
            <jaxb:package name="B" />
        </jaxb:schemaBindings>
    </jaxws:bindings>
</jaxws:bindings>

由于我在生成中没有任何错误消息,可能是因为用于访问导入模式的 XPath 表达式不好......

你们有什么线索吗?我有点卡在这里...

提前感谢您的投入!

4

2 回答 2

1

尝试编写绑定,就好像模式导入已合并到 WSDL 文档中一样,方法是直接引用其名称空间:

<jaxws:bindings wsdlLocation="WSDL_LOCATION" 
        xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        jaxb:version="2.0">
    <jaxws:bindings 
node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='A']">
        <jaxb:schemaBindings>
            <jaxb:package name="B" />
        </jaxb:schemaBindings>
    </jaxws:bindings>
</jaxws:bindings>

这对我有用。感谢这篇文章,它演示了如何使用导入的模式。

于 2013-09-19T06:39:36.810 回答
0

Interestingly, you've got no answers :) Unfortunately it is not possible to archive what you want. The only way is to define separate binding files for each schema file you have, that will work fine.

于 2011-06-14T11:33:31.273 回答