【问题标题】:undefined element declaration 'xs:schema'未定义的元素声明'xs:schema'
【发布时间】:2013-09-19 15:02:20
【问题描述】:

我对网络服务完全陌生。

我必须为 web 服务编写 rest web 服务客户端。 Web 服务在 SoapUI 上运行良好。该 URL 的 WSDL 文件已提供给我。但是当我在我的 Eclipse 项目中添加 wsdl 文件时,它给出了编译错误

src-resolve.4.2: Error resolving component 'xs:schema'. It was detected that 'xs:schema' is in namespace 'http://www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'. If this is the incorrect namespace, perhaps the prefix of 'xs:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:///E:/Ashish%20Workspace/HATStoLSAMS%20Webservice/HATS2LSAMSWS/WebContent/WEB-INF/wsdl/CorpsiteService.svc.wsdl'.

我用谷歌搜索了很多以摆脱这些错误,但没有任何效果。 如果我忽略错误并尝试使用 wsimport 以及 wsdl2java 命令创建存根 它给出了错误

[ERROR] undefined element declaration 'xs:schema'
line 1 of http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl

我正在使用下面的命令来生成存根

wsimport -d e:\test -s E:\wssrc http://chec.local/STAR.WCF/CorpsiteService.svc?singlewsdl -wsdllocation "../../../../../WEB-INF/wsdl/CorpsiteService.svc.wsdl"

我被困在这一点上,一整天都在为此苦苦挣扎。 任何有关这方面的帮助都会非常有帮助

【问题讨论】:

    标签: java web-services wsdl wsdl2java wsimport


    【解决方案1】:

    解决方案似乎是为xs:schema 提供替代绑定,如https://metro.java.net/2.1/guide/Dealing_with_schemas_that_are_not_referenced.html 中所述

    具体来说,对于经常导入命名空间xshttp://www.w3.org/2001/XMLSchema,还有一些额外的工作需要做。

    命令是:wsimport -b @987654323@ -b customization.xjb something.wsdl

    从上面链接的customization.xjb 位于https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjb 或从下面复制

    此自定义项的存在是为了处理可能因使用架构 Schema(在多个架构中作为相同名称空间导入)而产生的一些命名冲突。

    customization.xjb

    <?xml version="1.0" encoding="UTF-8"?>
    <bindings xmlns="http://java.sun.com/xml/ns/jaxb"
              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
              version="2.0">
    
      <globalBindings>
        <xjc:simple />
      </globalBindings>
    
      <bindings scd="~xsd:complexType">
        <class name="ComplexTypeType"/>
      </bindings>
    
      <bindings scd="~xsd:simpleType">
        <class name="SimpleTypeType"/>
      </bindings>
    
      <bindings scd="~xsd:group">
        <class name="GroupType"/>
      </bindings>
    
      <bindings scd="~xsd:attributeGroup">
        <class name="AttributeGroupType"/>
      </bindings>
    
      <bindings scd="~xsd:element">
        <class name="ElementType"/>
      </bindings>
    
      <bindings scd="~xsd:attribute">
        <class name="attributeType"/>
      </bindings>
    </bindings>
    

    我已经尝试使用这些文件以及与wsimport 关联的-b 参数,并且已经(显然)克服了这个错误(以及其他错误)。也就是说,我不能 100% 确定我的新错误不是部分由此引起的(因此这不是一个完整的答案)。如果没有实际的 wsdl 导致问题,则只能对解决问题(以及下一个问题)进行合理猜测。

    【讨论】:

    • 感谢@MichaelT 的简洁答案和提供的链接,为我解决了问题。
    • @jlr 感谢您让我知道它很有用。使用导致我这样做的 xsd,我永远无法解决错误并转而使用 apache 轴库来执行客户端,该客户端在其客户端中更加宽容/动态。也就是说,它在其客户端中也更加动态,并且没有 wsimport 为您提供的简单静态类型。
    • 我没有使用 wsimport 而是使用 Apache CXF 的 wsdl2java 工具来生成这些。我远离 Glassfish,因为过去我遇到了一些不相关的问题(关于自定义数据序列化,无论我尝试什么都不起作用,CXF 开箱即用!)。
    【解决方案2】:

    如果您使用 maven-jaxb2-plugin 代替 -b 提供所需的 URL 作为架构中的附加架构:

    <schema>
      <url>https://example.com/WebService.asmx?WSDL</url>
    </schema>
    <schema>
      <url>http://www.w3.org/2001/XMLSchema.xsd</url>
    </schema>
    

    您甚至可以将其保存在资源中,以便自动拾取

    【讨论】:

    • 这为我解决了这里的问题。
    【解决方案3】:

    我遇到了同样的问题,只需在 maven 插件中添加一行即可解决

    <args> 
        <arg>-b</arg>
        <arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
    </args>
    

    下面是我的maven插件

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
            <execution>
                <id>periodictableaccessws</id>
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                    <args>
                        <arg>-b</arg>
                        <arg>http://www.w3.org/2001/XMLSchema.xsd</arg>
                    </args>
                    <wsdlFiles>
                        <wsdlFile>doosdaas.wsdl</wsdlFile>
                    </wsdlFiles>
                    <packageName>com.dss.doosdaas</packageName>
                    <vmArgs>
                        <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
                        <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                    </vmArgs>
                    <!--   <bindingDirectory>${basedir}/src/main/resources/jaxb</bindingDirectory>
                       <bindingFiles>
                           <bindingFile>jaxb_binding.xjb</bindingFile>
                       </bindingFiles>-->
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      【解决方案4】:

      当我不得不使用一些 UE Taxations Customs Web 服务时,我遇到了这种错误。在之前的项目中我使用过user289086提出的解决方案

      但是对于最近的项目,我使用了另一种基于绑定但更短的解决方案,我使用此处描述的 Wrapper 样式规则 Using JAXB Data Binding

      1- 创建一个包含以下内容的绑定文件并将其添加到 META-INF 文件夹:

      <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
          <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
      </jaxws:bindings>
      

      2- 使用 wsimport 从 wsdl 创建 Web 服务引用(在我的例子中,我使用在后台使用 wsimport 的 Netbeans IDE WS 客户端助手),例如: UE CheckTinService

      注意:首先可能wsimport的过程可能是raise和error,但是添加或不添加之前的绑定的区别很容易检查。

      3- 在 .pom 文件中添加对相应 jaxws-maven-plugin 执行的绑定引用。对于示例,它保持如下:

      <plugin>
          <groupId>org.jvnet.jax-ws-commons</groupId>
          <artifactId>jaxws-maven-plugin</artifactId>
          <version>2.3</version>
          <executions>
              <execution>
                  <goals>
                      <goal>wsimport</goal>
                  </goals>
                  <configuration>
                      <wsdlFiles>
                          <wsdlFile>ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlFile>
                      </wsdlFiles>
                      <packageName></packageName>
                      <vmArgs>
                          <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                      </vmArgs>
                      <wsdlLocation>https://ec.europa.eu/taxation_customs/tin/checkTinService.wsdl</wsdlLocation>
                      <staleFile>${project.build.directory}/jaxws/stale/checkTinService.stale</staleFile>
                      <bindingFiles>
                          <bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
                      </bindingFiles>
                  </configuration>
                  <id>wsimport-generate-checkTinService</id>
                  <phase>generate-sources</phase>
              </execution>
          </executions>
          ...
      

      您可以看到使用之前创建的绑定文件的确切配置:

      <bindingFiles>
             <bindingFile>${basedir}/src/main/resources/META-INF/TaxationCustomsWsImportBindings.xml</bindingFile>
      </bindingFiles>
      

      4- 最后转向刷新de WS Reference,修改的内容会应用到wsimport的过程中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-02
        相关资源
        最近更新 更多