为此web方法
使用的类型指定XML
命名空间。仅适用于定义为web服务
或web客户端
的类。
若要重写类型的默认XML
命名空间(当该方法用作web方法时),请使用以下语法:
Method name(formal_spec) As returnclass [ SoapTypeNameSpace = "soapnamespace", SoapBindingStyle = document, WebMethod ]
{ //implementation }
其中soapnamespace
是命名空间URI
。请注意,如果URI
包含冒号(:
),则该字符串必须加引号。也就是说,可以使用以下内容:
Method MyMethod() [ SoapTypeNameSpace = "http://www.mynamespace.org", SoapBindingStyle = document, WebMethod ]
或以下内容:
Method MyMethod() [ SoapTypeNameSpace = othervalue, SoapBindingStyle = document, WebMethod ]
但不包括以下内容:
Method MyMethod() [ SoapTypeNameSpace = http://www.mynamespace.org, SoapBindingStyle = document, WebMethod ]
重要提示:对于手动创建的web服务
,该关键字的默认值通常是合适的。当使用SOAP向导从WSDL
生成web客户端
或服务时,InterSystems IRIS会将该关键字设置为适合该WSDL
;如果修改该值,web客户端
或服务可能不再工作。
此关键字指定此web方法
使用的类型的XML命名空间。
注意:只有当方法使用文档样式绑定时,此关键字才有作用。也就是说,方法(或包含它的类)必须用等于document
的SoapBindingStyle
标记。(对于使用rpc-style
绑定的方法,指定这个关键字是没有意义的。)
如果省略此关键字,则此方法的类型位于由web服务
或客户端
类的TYPENAMESPACE
参数指定的命名空间中。如果未指定TYPENAMESPACE
,则类型将位于由web服务
或客户端的are
参数指定的命名空间中。
SoapTypeNameSpace
关键字影响WSDL
的以下部分:
<definitions>
元素中的命名空间声明。指定的命名空间(例如,http://www.customtypes.org
)将添加到这里。例如:
...
xmlns:ns2="http://www.customtypes.org"
xmlns:s0="http://www.wbns.org"
xmlns:s1="http://webservicetypesns.org"
...
targetNamespace="http://www.wbns.org"
在本例中,http://www.customtypes.org
命名空间被分配给前缀ns2
。
请注意,WSDL
还像往常一样声明了以下名称空间:
-
Web服务
的命名空间(http://www.wsns.org
),在本例中,它被分配给前缀s0
,也用作Web服务
的目标命名空间。 - 网络服务的类型命名空间
http://www.webservicetypesns.org
),在本例中它被分配给前缀s1
。
如果在web服务
类中没有指定类型命名空间,则该命名空间不包含在WSDL
中。
-
<types>
元素,它包含一个<schema>
元素,该元素的targetNamespace
属性等于为SoapTypeNameSpace
指定的命名空间:
<types>
...
<s:schema elementFormDefault="qualified" targetNamespace="http://www.customtypes.org">
<s:element name="Add">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" name="a" type="s:decimal"/>
<s:element minOccurs="0" name="b" type="s:decimal"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AddResponse">
<s:complexType>
<s:sequence>
<s:element name="AddResult" type="s:decimal"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
...
</types>
相反,如果没有指定SoapTypeNameSpace
,那么WSDL
的这一部分将如下所示。请注意,<schema>
元素的targetNamespace
是web服务
类型的命名空间:
<types>
...
<s:schema elementFormDefault="qualified" targetNamespace="http://www.webservicetypesns.org">
<s:element name="Add">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" name="a" type="s:decimal"/>
<s:element minOccurs="0" name="b" type="s:decimal"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AddResponse">
<s:complexType>
<s:sequence>
<s:element name="AddResult" type="s:decimal"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
...
</types>
(此外,如果在web服务类
中没有指定类型命名空间,则targetNamespace
将改为web服务
的命名空间。)
SOAP
消息可能如下所示(为了可读性,添加了换行符和空格):
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:s='http://www.w3.org/2001/XMLSchema'>
<SOAP-ENV:Body>
<AddResponse xmlns="http://www.customtypes.org">
<AddResult>3</AddResult>
</AddResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
请注意,<AddResponse>
元素位于“http://www.customtypes.org”
命名空间中。
相反,如果没有指定SoapTypeNameSpace
关键字,则消息可以如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:s='http://www.w3.org/2001/XMLSchema'>
<SOAP-ENV:Body>
<AddResponse xmlns="http://www.webservicetypesns.org">
<AddResult>3</AddResult>
</AddResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>