我显然不了解如何在 WSDL 的 XML 中正确使用名称空间。有些东西没有点击。我剪掉了一段我们的 WSDL 来演示这个问题。请参阅下面的工作 WSDL。
当我使用 wsimport 从中生成代码时,它可以工作。当我尝试使用我定义的类型时,它没有。我在另一个问题中看到评论说:
For example, one does not have to use a prefix for the items defined in the schema,
that are later on referenced elsewhere in the same file (e.g. a global simpleType
used as a type for an attribute or element).
当我读到它时,我想我明白了。但我显然没有。
我使用的 JAX-WS 是:“JDK 6 中的 JAX-WS RI 2.1.6”
我在 WSDL 中添加了这个:
<xsd:complexType name="Void">
<xsd:sequence>
</xsd:sequence>
</xsd:complexType>
我将 HelloRequest 元素更改为:
<xsd:element name="HelloRequest" type="Void" />
我得到下面的错误。
“不必为架构中定义的项目使用前缀,这些项目稍后会在同一文件的其他地方引用......”
那句话是什么意思?我不认为这意味着我认为它意味着什么......
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://snip/LMSApp.woa/wa/soap"
targetNamespace="http://snip/LMSApp.woa/wa/soap">
<wsdl:types>
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://snip/LMSApp.woa/wa/soap">
<xsd:element name="HelloRequest">
<xsd:complexType>
<xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="HelloResponse">
<xsd:complexType>
<xsd:all>
<xsd:element name="version" type="xsd:string" />
<xsd:element name="results"><xsd:complexType><xsd:sequence><xsd:element name="result" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/></xsd:sequence></xsd:complexType></xsd:element>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="HelloRequestMessage">
<wsdl:part name="input" element="tns:HelloRequest"/>
</wsdl:message>
<wsdl:message name="HelloResponseMessage">
<wsdl:part name="output" element="tns:HelloResponse"/>
</wsdl:message>
<wsdl:portType name="LMSPortType">
<wsdl:operation name="Hello">
<wsdl:input name="HelloRequestMessage" message="tns:HelloRequestMessage"/>
<wsdl:output name="HelloResponseMessage" message="tns:HelloResponseMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="LMSBinding" type="tns:LMSPortType"><soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="Hello"><soap:operation soapAction="Hello"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding>
<wsdl:service name="LMSService">
<wsdl:port name="LMSPort" binding="tns:LMSBinding">
<soap:address location="http://snip/LMSApp.woa/wa/soap"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
运行 wsimport 的错误是:
[WARNING] src-resolve.4.1: Error resolving component 'Void'. It was detected that 'Void' has no namespace, but components with no target namespace are not referenceable from schema document 'http://snip/LMSService.woa/wa/hellowsdl#types?schema1'. If 'Void' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'Void' has no namespace, then an 'import' without a "namespace" attribute should be added to 'http://snip/LMSService.woa/wa/hellowsdl#types?schema1'.
line 16 of http://snip/LMSService.woa/wa/hellowsdl#types?schema1
[ERROR] undefined simple or complex type 'Void'
line 16 of http://snip/LMSService.woa/wa/hellowsdl
Exception in thread "main" java.lang.InternalError: unresolved reference
at com.sun.xml.internal.xsom.impl.parser.DelayedRef._get(DelayedRef.java:89)
at com.sun.xml.internal.xsom.impl.parser.DelayedRef$Type.getType(DelayedRef.java:134)
at com.sun.xml.internal.xsom.impl.ElementDecl.getType(ElementDecl.java:96)
at com.sun.xml.internal.xsom.impl.ElementDecl.updateSubstitutabilityMap(ElementDecl.java:160)
at com.sun.xml.internal.xsom.impl.parser.ParserContext.getResult(ParserContext.java:126)
at com.sun.xml.internal.xsom.parser.XSOMParser.getResult(XSOMParser.java:197)
at com.sun.tools.internal.xjc.ModelLoader.createXSOM(ModelLoader.java:508)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:226)
at com.sun.tools.internal.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:74)
at com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:123)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2234)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:176)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:122)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:172)
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 com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:111)
at com.sun.tools.internal.ws.WsImport.main(WsImport.java:41)