Java:在JAXWS 2.0中不支持RPC/encoded WSDL。

62

我正在使用CXF 2.1从wsdl生成Java代码,但是我遇到了以下错误:

WSDLToJava Error: Rpc/encoded wsdls are not supported in JAXWS 2.0

org.apache.cxf.tools.common.ToolException: Rpc/encoded wsdls are not supported in JAXWS 2.0
    at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.checkSupported(JAXWSDefinitionBuilder.java:141)
    at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:87)
    at org.apache.cxf.tools.wsdlto.frontend.jaxws.wsdl11.JAXWSDefinitionBuilder.build(JAXWSDefinitionBuilder.java:61)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:127)
    at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:232)
    at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:83)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:103)
    at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:173)

我该如何解决这个错误,我能使用之前的CXF版本或其他方法来解决吗?

7个回答

82

RPC/encoded是在XML Schema定义SOAP对象之前的遗留物,它已经不再被广泛支持。您需要使用Apache Axis 1.0生成存根,这是同一时代的产物。

java org.apache.axis.wsdl.WSDL2Java http://someurl?WSDL 

您需要在 -cp 类路径参数中使用以下 jar 包或等效物:

这将生成类似于wsimport的存根文件。
或者,如果您没有使用需要rpc/encoded的模式部分,则可以下载WSDL副本并注释掉这些部分。 然后针对本地文件运行wsimport。
如果查看WSDL,以下部分正在使用rpc/encoded:
<soap:body use="encoded"
           encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

3
互联网上有没有关于这个问题的文档可用? - Ganesh
2
在最新的Axis 1.4分发版中,我有不同的JAR命名,并且mail-1.4.jar不存在。它不能正常工作。(我按照您提供的Axis 1.0链接操作) - рüффп
您需要显式添加它。mail-1.x.jar和activation-1.x.jar。 - nikhil
我尝试了你的方法,但是出现了“java.net.ProtocolException: Server redirected too many times”的错误提示,这可能是因为我正在尝试从需要身份验证的 Web 服务中导入数据。请问如何使用你的方法进行身份验证处理? - Neo
我已经从soap:body中删除了use=encoded属性,然后wsimport不再抱怨并且生成了wsdl的工件。这是正确的方法吗?还是会有任何影响? - G.S.Tomar
1
@Albert,关于Maven请参考我下面的帖子。 - Foyta

20
我按照Chase Seibert建议,在他的答案中使用了Axis 1.4,尽管该答案给出的下载链接无法使用。我使用的替代下载链接提供了不同的库。以下是我生成代码所遵循的步骤。
前往http://apache.is.co.za/axis/axis/java/1.4/并下载axis-bin-1_4.zip
解压缩后,您应该拥有以下文件(以及其他文件):
  • axis.jar
  • commons-discovery-0.2.jar
  • commons-logging-1.0.4.jar
  • jaxrpc.jar
  • saaj.jar
  • wsdl4j-1.5.1.jar
使用以下命令执行WSDL2Java(当然要替换URL):
java -cp axis.jar;commons-logging-1.0.4.jar;commons-discovery-0.2.jar;jaxrpc.jar;saaj.jar;wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java http://someURL?WSDL

这将生成您的Java文件。
附注:使用Axis 1.2.1似乎同样有效。

4
报告有两个班级缺失,导致无法支持附件。解决方法是获取mail.jar和activation.jar并将它们添加到命令中。 - Marco Borchert
5
根据Marco Brochet所说的,需要添加mailapi.jar和activation.jar。我使用了-classpath并将“;”替换为“:”。命令为java -classpath axis.jar:commons-logging-1.0.4.jar:commons-discovery-0.2.jar:jaxrpc.jar:saaj.jar:wsdl4j-1.5.1.jar:mailapi.jar:activation.jar org.apache.axis.wsdl.WSDL2Java https://api.clickatell.com/soap/webservice.php?WSDL。 - Cedric Simon

7

如果有人想使用maven:(此处加上关于WSDL绑定样式的一些信息在这里

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>axistools-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                    <configuration>
                        <!-- Use your .wsdl location here-->
                        <sourceDirectory>${basedir}/src/main/resources/wsdl</sourceDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<!-- Here the libraries that you need to call the Axis WS client -->
<dependencies>
    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis-jaxrpc</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>commons-discovery</groupId>
        <artifactId>commons-discovery</artifactId>
        <version>0.5</version>
    </dependency>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis-wsdl4j</artifactId>
        <version>1.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis-saaj</artifactId>
        <version>1.4</version>
    </dependency>
    <!-- activation+mail: To stop Axis generating WARNING about "Attachment support being disabled" -->
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
</dependencies>

7
也许这可以帮助您解决CXF的问题。至少对我来说是有效的。 我编辑了WSDL文件,删除了所有SOAP-ENC的引用,并按以下方式创建了类型ArrayOfString。
<xsd:complexType name="ArrayOfString">
    <xsd:sequence>
      <xsd:element minOccurs="0" maxOccurs="unbounded" name="String" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

0

这是发生在我身上的事情(旧的wsdl文件与同一文件夹中):https://www.damirscorner.com/blog/posts/20180831-CodeGenerationWithMavenCxfPlugin.html

"显然,还有其他原因导致了Maven插件的问题。经过多次尝试和错误,我终于找到了问题的根源。同一文件夹中还有另一个WSDL文件,它用于RPC/literal网络服务。插件失败是因为它试图处理该文件,虽然在配置中我的WSDL路径的完整路径并没有以任何方式指向它。"


0
也许这对某人有帮助。我检查了上面的内容,但对我没有起作用。
我下载了Apache Axis 1.2.1,然后将命令改成了这样。
java -classpath full_path/commons-logging-1.0.4.jar:full_path/commons-discovery-0.2.jar:full_path/jaxrpc.jar:full_path/saaj.jar:full_path/wsdl4j-1.5.1.jar:full_path/mailapi.jar:full_path/activation.jar:full_path/mail.jar -Xmx128M org.apache.axis.wsdl.WSDL2Java -pcom.package -T1.1 -ofull_path_of_output file:full_path_of_wsdl

-4

只需提取并执行WSDL2Java?使用以下命令(当然要替换URL):

java -cp axis.jar;commons-logging-1.0.4.jar;commons-discovery-0.2.jar;jaxrpc.jar;saaj.jar;wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java http://someURL?WSDL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接