我对Web服务完全陌生。
我必须为 Web 服务编写休息 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"
我被困在这一点上,并且整天都在为此苦苦挣扎。有关此的任何帮助都将非常有帮助
此问题的解决方案似乎是为xs:schema
提供备用绑定,如 https://metro.java.net/2.1/guide/Dealing_with_schemas_that_are_not_referenced.html 中所述
具体来说,对于经常导入命名空间xs
的 http://www.w3.org/2001/XMLSchema,需要做一些额外的工作。
命令将是:wsimport -b http://www.w3.org/2001/XMLSchema.xsd -b customization.xjb something.wsdl
从上面链接的 custom.xjb 位于 https://www.java.net//blog/kohsuke/archive/20070228/xsd.xjb 或从下面复制
此自定义用于处理因使用架构架构(在多个架构中作为相同名称空间导入)而可能引起的一些命名冲突。
定制.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>
我已经尝试过使用这些文件和相关的-b
参数来wsimport
,并且(显然)克服了此错误(以及其他错误)。 也就是说,我不能 100% 确定我的新错误不是部分由此引起的(因此这不是一个完整的答案)。 如果没有实际的 wsdl 导致问题,人们只能对解决问题(以及下一个问题)进行合理的猜测。
如果您使用的是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>
您甚至可以将其保存在资源中,以便自动拾取
我遇到了同样的问题,只需在 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>
当我不得不使用一些UE Taxations Customs Web服务时,我遇到了这种错误。在以前的项目中,我使用了user289086提出的解决方案
但是对于最近的项目,我使用了另一个同样基于绑定但更短的解决方案,其中我使用此处描述的包装器样式规则使用 JAXB 数据绑定。
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 服务引用(在我的例子中,我使用 Netbeans IDE WS Client Assistant 在后台使用 wsimport),例如:UE CheckTinService
注意:首先,也许wsimport的过程可能会引发和错误,但是添加或不添加先前绑定的差异很容易检查。
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 参考,更改将应用于 wsimport 的过程。