Web Services 单击将SOAP wsdl转换为JAXB java类

pxy2qtax  于 2022-11-15  发布在  Java
关注(0)|答案(5)|浏览(201)

我尝试从Clickatell wsdl生成JAXB类:您可以在这里找到wsdl定义,它相当大:http://api.clickatell.com/soap/webservice.php?WSDL
当我尝试从这个Wsdl生成java类时,出现了以下错误:[错误]未定义的简单或复杂型别'SOAP-ENC:Array' [错误]未定义的属性'SOAP-ENC:arrayType'
我希望有人能帮我。干杯,蒂姆

58wvjzkj

58wvjzkj1#

您的模式引用了模式xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/中定义的类型SOAP-ENC:Array,但该模式未包含在wsdl中。
我遇到了类似的问题,不得不使用目录告诉jaxb/xjc在哪里可以找到模式。
转到http://schemas.xmlsoap.org/soap/encoding/并另保存为soapenc.xsd
然后创建包含以下内容的纯文本文件

PUBLIC "http://schemas.xmlsoap.org/soap/encoding/" "soapenc.xsd"

然后将该文件作为目录文件传递给xjc
更新:如果你是对maven,这是如何将所有挂在一起。
将架构、soapenc.xsd和catalog.cat(纯文本文件)放在src/main/resources中
然后告诉jaxb插件将目录传递给xjc

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <executions>
      <execution>
        <id>wsdl-generate</id>
        <configuration>
          <schemaIncludes>
            <include>*.wsdl</include>
          </schemaIncludes>
          <catalog>${project.basedir}/src/main/resources/catalog.cat</catalog>
        </configuration>
        <goals>
          <goal>generate</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
y4ekin9u

y4ekin9u2#

我认为最好的方法是使用旧的good axis 1. 4。它被设计为与rpc服务一起工作,它通常完成它的工作。主要的问题是这个库非常非常旧(jar在2006年被上传到中央),它不再被维护了。
如果您决定给予一下,只需将以下依赖项添加到您的pom中:

<dependency>
    <groupId>axis</groupId>
    <artifactId>axis</artifactId>
    <version>1.4</version>
</dependency>

添加以下插件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>axistools-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>javax.activation-api</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
    </dependencies>
    <configuration>
        <sourceDirectory>${project.basedir}/src/main/resources</sourceDirectory>
        <wsdlFiles>
            <wsdlFile>my_service.wsdl</wsdlFile>
        </wsdlFiles>
    </configuration>
</plugin>

把你的wsdl文件放到src/main/resources/my_service.wsdl中,然后用mvn clean package构建应用程序。
插件详细信息可在here中找到

q1qsirdb

q1qsirdb3#

请查看www.example.com上的WS-I基本配置文件-1.1规范http://www.ws-i.org/Profiles/BasicProfile-1.1.html#soapenc_Array
上面写着:
R2110在说明中,声明不得扩展或限制soapenc:Array类型。
R2111在说明中,声明不得在类型声明中使用wsdl:arrayType属性。
R2112在描述中,元素不应使用ArrayOfXXX约定命名。
R2113信封不得包含soapenc:arrayType属性。
哟!

vc9ivgsu

vc9ivgsu4#

我在使用axis1.5的wsdl2java实用程序时,我们在数组上遇到了类似的错误。

Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
            at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:271)
            at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
            at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
            at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:53)
            at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:224)
            ... 2 more
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:50)
            ... 3 more
    Caused by: org.apache.axis2.schema.SchemaCompilationException: can not find type {http://schemas.xmlsoap.org/soap/encoding/}Array from the parent schema ....
            at org.apache.axis2.schema.SchemaCompiler.copyMetaInfoHierarchy(SchemaCompiler.java:1296)
            at org.apache.axis2.schema.SchemaCompiler.processComplexContent(SchemaCompiler.java:1258)
            at org.apache.axis2.schema.SchemaCompiler.processContentModel(SchemaCompiler.java:1153)
            at org.apache.axis2.schema.SchemaCompiler.processComplexType(SchemaCompiler.java:1097)
            at org.apache.axis2.schema.SchemaCompiler.processNamedComplexSchemaType(SchemaCompiler.java:1017)

正如上面关于soapenc.xsd的回答之一所解释的,我尝试通过使用网站“http://schemas.xmlsoap.org/soap/encoding/”的内容创建soapenc.xsd来更新我的wsdl文件。如下所示,这对我来说真的很有效。

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1= .. xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns=.. xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace=..>
<types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace=.. xmlns:ns1=.. xmlns:ns2=.. xmlns:tns=.. xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
</types>
<import location="soapenc.xsd" namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<message name="Input">
    <part name=../>
</message>
<message name="Output">
    <part name=../>
</message>
<portType name=".."> .. </portType>
<binding name="..." type="tns:"..">
    <operation name="...">          ..          </operation>
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
</binding>
<service name="...">
    <port binding="tns:..." name="...">         <soap:address location="..."/>      </port>
</service>
rt4zxlrg

rt4zxlrg5#

JAXB不支持RPC/编码。请使用JAX-RPC来解决此问题。

相关问题