WSDL中用户定义类型的命名空间?

时间:2013-09-17 18:41:16

标签: web-services wsdl jax-ws

我显然没有讨论如何在WSDL的XML中正确使用名称空间。有些事情没有点击过。我删掉了一段WSDL来演示这个问题。请参阅下面的工作WSDL。

当我使用wsimport从中生成代码时,它可以工作。当我尝试使用我定义的类型时,它没有。我在another question中看到了一条评论说:

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" />

我收到以下错误。

&#34;人们不必为模式中定义的项目使用前缀,这些项目稍后将在同一文件中的其他位置引用...&#34;

这句话是什么意思?我认为这并不意味着我的意思......

<?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)

1 个答案:

答案 0 :(得分:1)

我不知道是否对这个答案感到惊讶。

我定义的complexType位于架构的targetNamespace中。我有:

<xsd:schema elementFormDefault="qualified"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://snip/LMSService.woa/wa/mebsoap">

    <xsd:complexType name="Void">
        <xsd:all></xsd:all>
    </xsd:complexType>

    <xsd:element name="HelloRequest" type="Void" />
    ....

我需要使用:

<xsd:schema elementFormDefault="qualified"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tns="http://snip/LMSService.woa/wa/mebsoap"
            targetNamespace="http://snip/LMSService.woa/wa/mebsoap">

    <xsd:complexType name="Void">
        <xsd:all></xsd:all>
    </xsd:complexType>

    <xsd:element name="HelloRequest" type="tns:Void" />
    ....

这就是全部!