Reputation: 3619
I obviously am not grokking something about how to properly use namespaces in the XML of a WSDL. Something has just not clicked. I cut out a piece of our WSDL to demonstrate this problem. See below for the working WSDL.
When I use wsimport to generate code from this, it works. When I try to use a type that I defined, it does not. I saw a comment in another question that said:
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).
When I read that, I think I understand it. But I obviously do not.
The JAX-WS I am using is: "JAX-WS RI 2.1.6 in JDK 6"
I added this to the WSDL, inside the :
<xsd:complexType name="Void">
<xsd:sequence>
</xsd:sequence>
</xsd:complexType>
And I changed the HelloRequest element to:
<xsd:element name="HelloRequest" type="Void" />
And I get the error below.
"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..."
What does that sentence mean? I do not think it means what I think it means....
<?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>
and the error from running the wsimport is:
[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)
Upvotes: 0
Views: 6593
Reputation: 3619
I do not know whether to be surprised about this answer or not.
The complexType I am defining is in the targetNamespace for the schema. I had:
<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" />
....
I needed to use:
<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" />
....
And that was all it took!
Upvotes: 1