簡體   English   中英

未定義的元素聲明 'xs:schema'

[英]undefined element declaration 'xs:schema'

我對網絡服務的東西完全陌生。

我必須為網絡服務編寫休息網絡服務客戶端。 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"

我被困在這一點上,並且一整天都在為此而苦苦掙扎。 任何有關這方面的幫助都會非常有幫助

對此的解決方案似乎是為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 http://www.w3.org/2001/XMLSchema.xsd -b customization.xjb something.wsdl

從上面鏈接的customization.xjb 位於https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjb或從下面復制

這種定制的存在是為了處理使用模式 Schema(在多個模式中作為相同的命名空間導入)可能產生的一些命名沖突。

定制.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,人們只能對解決問題(以及下一個問題)進行合理的猜測。

我遇到了同樣的問題,只需在 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>

如果您使用 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>

您甚至可以將其保存在資源中,以便自動拾取

當我不得不使用一些 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- 最后轉向refresh de WS Reference,更改將應用​​於wsimport 的過程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM