3

我尝试从这个 WSDL生成存根(不是我的网络服务,所以我不能更改名称!)

问题是我无法成功生成存根,因为在 wsdl 中是服务名称,其不同之处仅在于带有“_”的服务开始而另一个不是。示例:_registerTest 和 registerTest

有人知道如何解决这个问题吗?是否可以使用 Jaxb 生成存根?

我尝试使用 Maven:

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.7.1</version>
            <executions>
                <execution>
                    <id>ws-source-gen-phase1</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <removeOldOutput>true</removeOldOutput>
                        <extension>true</extension>
                        <schemaDirectory>src/main/resources/</schemaDirectory>
                        <args>
                            <arg>-wsdl</arg>
                            <schemaFiles>src/main/resources/onyxexamservices.wsdl</schemaFiles>
                            <!-- <arg>-XautoNameResolution</arg>  -->
                        </args>
                        <generatePackage>com.onyx.player.ws</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

并使用 wsimport:

wsimport onyxexamservices.wsdl

parsing WSDL...

Generating code...

Compiling code...

/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:89: error: 
method registerTest(long,String,byte[],Mapwrapper) is already defined in interface 
OnyxExamService
public long registerTest(
            ^
/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:114: error:  
method registerStudent(long,long,byte[],Mapwrapper) is already defined in interface    
OnyxExamService
public long registerStudent(
            ^
/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:165: error:  
method testControl(long,StudentIdsWrapper,int,Mapwrapper) is already defined in interface 
OnyxExamService
public long testControl(
            ^
/Users/blub/Downloads/./de/bps/plugin/webservice/server/OnyxExamService.java:210: error: 
method deregisterTest(long,String,Mapwrapper) is already defined in interface 
OnyxExamService
public long deregisterTest(
            ^
4 errors
compilation failed, errors should have been reported
4

1 回答 1

3

我认为删除下划线是为了生成尊重Java 代码约定的名称(foo_barfooBar在源代码中生成的名称)。

如果要保留名称,可以应用一些自定义项

假设我有我正在处理的文件c:\temp\src并且我正在生成源代码c:\temp\dest,我可以(在一行上):

wsimport 
         -keep 
         -d c:\temp\dest 
         -b c:\temp\src\fix.xml 
c:\temp\src\onyxexamservices.wsdl

fix.xml我的自定义文件在哪里:

<jaxws:bindings wsdlLocation="C:\temp\src\onyxexamservices.wsdl"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_registerStudent']">
        <jaxws:method name="_registerStudent" />
    </jaxws:bindings>
    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_registerTest']">
        <jaxws:method name="_registerTest" />
    </jaxws:bindings>
    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_testControl']">
        <jaxws:method name="_testControl" />
    </jaxws:bindings>
    <jaxws:bindings node="wsdl:definitions/wsdl:portType[@name='OnyxExamService']/wsdl:operation[@name='_deregisterTest']">
        <jaxws:method name="_deregisterTest" />
    </jaxws:bindings>
</jaxws:bindings>
于 2013-06-09T07:36:12.233 回答