28

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="getTimeAsElapsed" 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?

Brady Moritz
  • 8,624
  • 8
  • 66
  • 100
Vicky
  • 5,380
  • 18
  • 60
  • 83
  • 2
    Just a sanity check here (those dashes in your example makes me suspicious): If I look at an XML document (schema or otherwise) in Firefox, it does some styling to the document, for example it removes namespace declarations. Right click -> View Page Source brings back the original – forty-two Jun 06 '11 at 21:41
  • @Per, you were right. I could see the prefix and other details by looking at source. When I switched on to IE, I could see all other namespace declaration too... – Vicky Jun 07 '11 at 02:57

2 Answers2

51

As per w3, tns means "this namespace", referring to the current document.

Source: https://www.w3.org/TR/wsdl.html#_notational

Michael
  • 7,348
  • 10
  • 49
  • 86
Scott Brickey
  • 1,207
  • 12
  • 22
0

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.

Amila Suriarachchi
  • 1,228
  • 7
  • 5