首页 > 解决方案 > 如何绑定多个wsdl文件?

问题描述

我致力于通过 WSDL 文件升级某个客户提供的服务。在之前的版本中,这些服务在单个 WSDL 文件中提供,为此我使用单个 bindings.xml 文件来处理定制部分。现在,这些服务在多个 WSDL 文件(总共 9 个)中提供,这些文件之间具有内部引用。我想我需要多个绑定文件来处理自定义。但是, wsimport 似乎不适用于这种方法。

我努力了:

  1. 更改 wsdlLocation 属性的现有位置以指向需要自定义的最新 WSDL 文件之一;还必须处理其他文件以进行自定义,如何使用 bindings.xml 文件中的单个 wsdlLocation 属性来做到这一点?

  2. 在每个文件中添加多个具有 wsdlLocation 属性的绑定文件以指向其对应的 wsdl 文件,在这种情况下,由于 xml 文件和 wsdl 文件之间存在不匹配,我会遇到编译错误。

    3.尝试将 wsdl 文件分离到不同的文件夹中并单独编译,由于内部引用,这当然不起作用。我猜所有的都将在一个目标中执行。

pom.xml:


<plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>${jaxws-maven-plugin.version}</version>
            <executions>
                <execution>
                    <id>etc</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
                        <keep>true</keep>
                        <verbose>true</verbose>
                        <wsdlDirectory>src/main/resources/META-INF/wsdl</wsdlDirectory>
                        <wsdlFiles>

                            <wsdlFile>Service1.wsdl</wsdlFile>

                            <wsdlFile>Service2.wsdl</wsdlFile>

                        </wsdlFiles>
                        <bindingDirectory>src/main/resources/META-INF/wsdl</bindingDirectory>
                        <bindingFiles>
                            <bindingFileService1bindings.xml</bindingFile>
                            <bindingFile>Service2bindings.xml</bindingFile>

                        </bindingFiles>
                        <quiet>true</quiet>
                        <packageName>com.etc.sim.impl</packageName>
                        <staleFile>${project.build.directory}/etc.done</staleFile>
                        <xjcArgs>
                            <xjcArg>-npa</xjcArg>
                        </xjcArgs>
                    </configuration>


                </execution>
            </executions>
        </plugin>
        <plugin>

Service1bindings.xml

<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" wsdlLocation="Service1.wsdl">

    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='ServiceMgmt']/wsdl:operation[@name='addEventsToPackage']">
        <jaxws:parameter part="wsdl:definitions/wsdl:message[@name='addEventsToPackageRequest']/wsdl:part[@name='package']"
            childElementName="package" name="paramPackage" />
    </jaxws:bindings>

    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='ServiceMgmt']/wsdl:operation[@name='removeEventsFromPackage']">
        <jaxws:parameter
            part="wsdl:definitions/wsdl:message[@name='removeEventsFromPackageRequest']/wsdl:part[@name='package']"
            childElementName="package" name="paramPackage" />
    </jaxws:bindings>
</jaxws:bindings>

Service2bindings.xml

<jaxws:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" wsdlLocation="service2.wsdl">

    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='Service2Mgmt']/wsdl:operation[@name='addEventsToPackage']">
        <jaxws:parameter part="wsdl:definitions/wsdl:message[@name='addEventsToPackageRequest']/wsdl:part[@name='package']"
            childElementName="package" name="paramPackage" />
    </jaxws:bindings>

    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='Service2Mgmt']/wsdl:operation[@name='removeEventsFromPackage']">
        <jaxws:parameter
            part="wsdl:definitions/wsdl:message[@name='removeEventsFromPackageRequest']/wsdl:part[@name='package']"
            childElementName="package" name="paramPackage" />
    </jaxws:bindings>
</jaxws:bindings>

The build with mvn clean install gives below error all the time: 

*****************************************************************************
Processing: file:sim/src/main/resources/META-INF/wsdl/Service2.wsdl
[INFO] jaxws:wsimport args: [-keep, -s, target/generated-sources/jaxws-wsimport, -verbose, -encoding, UTF-8, -Xnocompile, -p, com.etc.sim.impl, -quiet, -B-npa, -b, sim/src/main/resources/META-INF/wsdl/Service1bindings.xml, -b, sim/src/main/resources/META-INF/wsdl/service2binding.xml, file:/opt/code/iap-test/tools/iap-simulators/vcas-sim/src/main/resources/META-INF/wsdl/service1.wsdl]
[ERROR]     "file:-sim/src/main/resources/META-INF/wsdl/Service2.wsdl" is not a part of this compilation. Is this a mistake for "file:/opt/code/iap-test/tools/iap-simulators/vcas-sim/src/main/resources/META-INF/wsdl/Service1.wsdl"?
  line 4 of file:sim/src/main/resources/META-INF/wsdl/Service2binding.xml

    Failed to parse the WSDL.
******************************************************************************

标签: web-servicesjaxbjax-ws-customizationjaxws-maven-plugin

解决方案


推荐阅读