文章
· 八月 9, 2021 阅读大约需 6 分钟

方法关键字SoapRequestMessage,SoapTypeNameSpace,SqlName,SqlProc

第八十一章 方法关键字 - 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命名空间。

注意:只有当方法使用文档样式绑定时,此关键字才有作用。也就是说,方法(或包含它的类)必须用等于documentSoapBindingStyle标记。(对于使用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>元素的targetNamespaceweb服务类型的命名空间:

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

其中sqlnameSQL标识符。

详解

如果将此方法投影为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存储过程不可用。

讨论 (0)1
登录或注册以继续