xml tns 出现在 Web 服务模式中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6255155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 14:47:14  来源:igfitidea点击:

tns appearing in Web Services schema

xmlweb-serviceswsdlxsdjax-ws

提问by Vicky

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:

我正在使用 JAX-WS 来运行一些示例 Web 服务。发布 Web 服务后,当我输入 WSDL URL 时,我可以看到 WSDL 文档。WSDL 文档指的是一个像这样的 Schema 文档:

<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:

我的问题是为什么“tns”出现在元素声明中?例如:

<xs:element name="getTimeAsElapsed" type="tns:getTimeAsElapsed"/>

<xs:element name="getTimeAsElapsed" type="电话:getTimeAsElapsed"/>

I've nowhere is the schema document seeing 'tns' to be declared as namespace prefix, the schema document simply starts with

我无处是模式文档看到“tns”被声明为命名空间前缀,模式文档只是以

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

那么为什么在引用其他元素时会出现“tns”呢?这是 JAX-WS 生成的 XML 模式的默认行为吗?

回答by Scott Brickey

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

根据 w3,tns 的意思是“这个命名空间”,指的是当前文档。

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

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

回答by Amila Suriarachchi

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.

您需要将整个 wsdl 文档视为一个大的 xml 文件。在这种情况下,使用在子元素的根元素(定义元素)中声明的命名空间前缀是有效的。

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.

不需要在架构(架构元素)根元素中声明 tns 命名空间。但是,如果您将架构分离到一个文件中,那么您需要具有 tns 前缀。