这是我参与8月更文挑战的第10活动详情查看:8月更文挑战
第八十一章 方法关键字 – SoapRequestMessage
当多个web方法
具有相同的SoapAction
时使用此方法。
在默认场景中,该关键字指定请求消息的SOAP
正文中的顶级元素的名称。
仅适用于定义为web服务
或web客户端
的类。
用法
要在请求消息的SOAP
体中指定顶级元素的名称,请使用以下语法:
Method name(formal_spec) As returnclass [ WebMethod, SoapAction = "MyAct", SoapRequestMessage="MyReqMessage" ]
{ //implementation }
复制代码
其中soaprequestmessage
是有效的XML标识符。
详解
注意:此关键字仅对包装的文档/文字document/literal
消息有效。
对于包装的文档/文字消息,该关键字指定请求消息的SOAP
主体中的顶部元素的名称。(默认情况下,包装文档/文字消息。
如果对同一web服务
中的多个web方法
使用相同的SoapAction
值,请指定此关键字。否则,一般不需要这个关键字。
与WSDL的关系
SoapRequestMessage
关键字影响web服务
的WSDL
的<Message>
部分。例如,考虑以下web方法:
Method Add(a as %Numeric,b as %Numeric) As %Numeric [ SoapAction = MyAct,SoapRequestMessage=MyReqMessage, WebMethod ]
{
Quit a + b
}
复制代码
对于这个web服务,WSDL包含以下内容:
<message name="AddSoapIn">
<part name="parameters" element="s0:MyReqMessage"/>
</message>
<message name="AddSoapOut">
<part name="parameters" element="s0:AddResponse"/>
</message>
复制代码
这些元素在<types>
部分中相应地定义。
默认情况下,如果方法没有指定SoapRequestMessage
关键字,<message>
部分将改为如下所示:
<message name="AddSoapIn">
<part name="parameters" element="s0:Add"/>
</message>
<message name="AddSoapOut">
<part name="parameters" element="s0:AddResponse"/>
</message>
复制代码
如果使用SOAP
向导从WSDL
IRIS web服务
或客户端, IRIS将此关键字设置为适合该WSDL的。
对Message的影响
对于前面显示的web方法
,web服务
需要以下形式的请求消息:
<?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>
<MyReqMessage xmlns="http://www.myapp.org"><a>1</a><b>2</b></MyReqMessage>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
复制代码
相反,如果该方法没有指定SoapRequestMessage
关键字,则该消息将如下所示:
<?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>
<Add xmlns="http://www.myapp.org"><a>1</a><b>2</b></Add>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
复制代码
第八十二章 方法关键字 – SoapTypeNameSpace
为此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
参数指定的命名空间中。
与WSDL的关系
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>
复制代码
第八十三章 方法关键字 – SqlName
覆盖投影SQL
存储过程的默认名称。
仅当此方法被投影为SQL
存储过程时应用。
用法
要覆盖方法投射为SQL
存储过程时使用的默认名称,请使用以下语法:
ClassMethod name(formal_spec) As returnclass [ SqlProc, SqlName = sqlname ]
{ //implementation }
复制代码
其中sqlname
是SQL
标识符。
详解
如果将此方法投影为SQL
存储过程,则使用此名称作为存储过程的名称。
默认
如果忽略这个关键字, IRIS确定SQL
名称如下:
CLASSNAME_METHODNAME
复制代码
默认使用大写字母。
但是,在调用存储过程时可以使用任何情况,因为SQL是不区分大小写的。
因此,在下面的示例中,默认的SQL name
值是TEST1_PROC1
。
这个默认值是在SELECT
语句中指定的:
Class User.Test1 Extends %Persistent
{
ClassMethod Proc1(BO,SUM) As %INTEGER [ SqlProc ]
{
///definition not shown
}
Query Q1(KD As %String,P1 As %String,P2 As %String) As %SqlQuery
{
SELECT SUM(SQLUser.TEST1_PROC1(1,2)) AS Sumd
FROM SQLUser.Test1
}
}
复制代码
第八十四章 方法关键字 – SqlProc
指定是否可以作为SQL
存储过程调用该方法。
只有类方法(而不是实例方法)可以作为SQL存储过程调用。
用法
要指定该方法可以作为SQL
存储过程调用,请使用以下语法:
ClassMethod name(formal_spec) As returnclass [ SqlProc ]
{ //implementation }
复制代码
否则,忽略该关键字或将Not
放在该关键字之前。
详解
该关键字指定可以作为SQL
存储过程调用该方法。
只有类方法(而不是实例方法)可以作为SQL
存储过程调用。
存储过程由子类继承。
默认
如果忽略此关键字,则该方法作为SQL
存储过程不可用。