tns appearing in Web Services schema
I'm using JAX-WS for running some sample Web services. After publishing the web services, when I typed the WSDL URL, I could see the WSDL document. WSDL document refers a Schema document that goes like this:
<xs:schema version="1.0" targetNamespace="http://ts.ch01/">
<xs:element name="getTimeAsElapsed" type="tns:getTimeAsElapsed"/>
<xs:element name="getTimeAsElapsedResponse" type="tns:getTimeAsElapsedResponse"/>
<xs:element name="getTimeAsString" type="tns:getTimeAsString"/>
<xs:element name="getTimeAsStringResponse" type="tns:getTimeAsStringResponse"/>
−
<xs:complexType name="getTimeAsString">
<xs:sequence/>
</xs:complexType>
−
<xs:complexType name="getTimeAsStringResponse">
−
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
−
<xs:complexType name="getTimeAsElapsed">
<xs:sequence/>
</xs:complexType>
−
<xs:complexType name="getTimeAsElapsedResponse">
−
<xs:sequence>
<xs:element name="return" type="xs:long"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
My question is why is 'tns' appearing in the element declaration? For example:
<xs:element name="getTimeAsE开发者_如何学编程lapsed" type="
tns:getTimeAsElapsed"/>
I've nowhere is the schema document seeing 'tns' to be declared as namespace prefix, the schema document simply starts with
<xs:schema version="1.0" targetNamespace="http://ts.ch01/">
Then why 'tns' is appearing when referencing other elements? Is this by default behaviour of XML schema generated by JAX-WS?
As per w3, tns means "this namespace", referring to the current document.
Source: https://www.w3.org/TR/wsdl.html#_notational
you need to think the whole wsdl document as a one big xml file. In that case using a namespace prefix declared at the root element (Definition element) at the child element is valid.
There is no requirement to have tns namespace declared at the schema (schema element) root element. But if you separated out the schema apart to one file then you need to have the tns prefix.
精彩评论