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

方法关键字Requires,ReturnResultsets,ServerOnly,SoapAction

第七十三章 方法关键字 - Requires

指定用户或进程调用此方法必须拥有的权限列表。

用法

要指定此方法应限于具有指定权限的用户或进程,请使用以下语法:

Method name(formal_spec) As returnclass [ Requires = privilegelist ] 
{    //implementation } 

其中,privilegelist 要么是单个特权,要么是用引号括起来的以逗号分隔的特权列表。
每个权限都采用resource:permission的形式,其中permissionUseReadWrite(或单字母缩写URW)。

若要为一个资源resource指定多个权限,请使用单字母缩写。

详情

用户或进程必须拥有权限列表中的所有权限才能调用该方法。
调用没有指定权限的方法会导致<PROTECT>错误。

如果方法从超类继承了Requires关键字,则可以通过设置关键字的新值将其添加到所需特权的列表中。
不能以这种方式删除所需的特权。

默认

如果忽略此关键字,则调用此方法不需要特殊权限。

示例

下面的方法需要对Sales数据库的读权限和对Marketing数据库的写权限。
(注意,如果一个数据库有写权限,它会自动有读权限。)

ClassMethod UpdateTotalSales() [ Requires = "%DB_SALES: Read, %DB_MARKETING: Write" ]
{
   set newSales = ^["SALES"]Orders
   set totalSales = ^["MARKETING"]Orders
   set totalSales = totalSales + newSales
   set ^["MARKETING"]Orders = totalSales
}

若要为一个资源指定多个权限,请使用单字母缩写。
以下两种方法在功能上是等价的:

ClassMethod TestMethod() [ Requires = "MyResource: RW" ]
{
   write "You have permission to run this method"
}

ClassMethod TestMethodTwo() [ Requires = "MyResource: Read, MyResource: Write" ]
{
   write "You have permission to run this method"
}

第七十四章 方法关键字 - ReturnResultsets

指定此方法是否返回结果集(以便ODBCJDBC客户机能够检索它们)。

用法

要指定该方法返回至少一个结果集,请使用以下语法:

ClassMethod name(formal_spec) As returnclass [ ReturnResultsets, SqlName = CustomSets, SqlProc ]  
{    //implementation }

否则,忽略此关键字或将单词Not紧接在关键字之前。

详解

此关键字指定该方法至少返回一个结果集。如果方法可能返回一个或多个结果集,则将此关键字设置为true。如果没有,xDBC客户端将无法检索结果集。

默认

如果省略此关键字,xDBC客户端将无法检索结果集。

第七十五章 方法关键字 - ServerOnly

指定此方法是否将被投影到Java客户端。

用法

将方法投影到Java客户端,请使用以下语法:

Method name(formal_spec) As returnclass [ ServerOnly=n ] 
{    //implementation }

其中n为下列其中之一:

  • 0表示该方法可以映射。
  • 1表示该方法不会被映射。

详解

该关键字指定方法不会被投影到Java客户机。

提示

要查看类的哪些方法是server-only的,请在终端中使用以下实用程序:

do dumpMethods^%occLGUtil("Sample.Person")  

参数是完全限定类名。
该实用程序生成一个报告,该报告指出关于每个方法的基本信息:该方法是否为存根,该方法是否仅为服务器,以及(如果该方法是从某个属性派生的)派生该方法的属性。

默认

如果忽略这个关键字,这个方法如果是存根方法就不会被投影(但是如果不是存根方法就会被投影)。

DHC-APP>do dumpMethods^%occLGUtil("Sample.Person")

Method=%%OIDGet UseStub=0 serveronly=1
Method=%%OIDIsValid UseStub=1 serveronly=0 PropName=%%OID MethodName=IsValid
Method=%%OIDSet UseStub=1 serveronly=1 PropName=%%OID MethodName=Set
Method=%1Check UseStub=0 serveronly=1
Method=%AcquireLock UseStub=0 serveronly=1
Method=%AddJrnObjToSyncSet UseStub=0 serveronly=1
Method=%AddToSaveSet UseStub=0 serveronly=1

第七十六章 方法关键字 - SoapAction

指定当通过HTTP将此方法作为web方法调用时,要在HTTP头中使用的SOAP操作。仅适用于定义为web服务web客户端的类。

用法

要指定将此方法用作web方法时在HTTP头中使用的SOAP操作,请使用以下语法:

Method name(formal_spec) As returnclass [ WebMethod, SoapAction = soapaction ] 
{    //implementation }

其中soapaction是下列之一:
- “[default]”—SOAP操作的默认值,即NAMESPACE/Package.Class.Method
- "customValue" -使用customValue作为SOAP操作。
该值应该是标识SOAP请求意图的URI

如果指定了一个自定义的值,它必须在web服务的每个web方法中是唯一的,或者你必须为每个web方法指定SoapRequestMessage关键字(并且为该关键字使用唯一的值)。
- "" -使用空值作为SOAP操作。这种情况很少见。

详情

web方法SOAP动作通常用于路由请求SOAP消息
例如,防火墙可以使用它来适当地过滤SOAP请求消息
InterSystems IRIS web服务使用SOAP操作(与消息本身结合)来确定如何处理请求消息。

该关键字允许指定在作为web方法调用此方法时使用的HTTP SOAP动作。
对于SOAP 1.1, SOAP动作包含在SOAPAction HTTP报头中。
对于SOAP 1.2,它包含在Content-Type HTTP报头中。

默认

如果忽略SoapAction关键字,SOAP动作的形式如下:

NAMESPACE/Package.Class.Method

其中NAMESPACEweb服务NAMESPACE参数的值,Package.Classweb服务类的名称,Methodweb方法的名称。

WSDL的关系

SoapAction关键字影响web服务WSDL的<binding>部分。
例如,以下web方法:

Method Add(a as %Numeric,b as %Numeric) As %Numeric [ SoapAction = MySoapAction,WebMethod ]
{
    Quit a + b
}

对于这个web服务WSDL<binding>部分如下所示:

<binding name="MyServiceNameSoap" type="s0:MyServiceNameSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="Add">
        <soap:operation soapAction="MySoapAction" style="document"/>
        <input>
            <soap:body use="literal"/>
        </input>
        <output>
            <soap:body use="literal"/>
        </output>
    </operation>
</binding>

默认情况下,如果方法没有指定SoapAction关键字,<soap:operation>元素可能会像下面这样:

<soap:operation soapAction="http://www.mynamespace.org/ROBJDemo.BasicWS.Add" style="document"/>

如果使用SOAP向导从WSDL生成 web服务服务或客户端,将此关键字设置为适合于该WSDL的关键字。

对消息的影响

对于前面显示的web方法web服务期望收到以下形式的请求消息(对于SOAP 1.1):

POST /csp/gsop/ROBJDemo.BasicWS.cls HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; InterSystems IRIS;)
Host: localhost:8080
Connection: Close
Accept-Encoding: gzip
SOAPAction: MySoapAction
Content-Length: 379
Content-Type: text/xml; charset=UTF-8

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope >...

默认情况下,如果方法没有指定SoapAction关键字,SoapAction行可能会像下面这样:

SOAPAction: http://www.mynamespace.org/ROBJDemo.BasicWS.Add

注意,对于SOAP 1.2,细节略有不同。
在这种情况下,web服务期望收到如下形式的请求消息:

POST /csp/gsop/ROBJDemo.BasicWS.cls HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; InterSystems IRIS;)
Host: localhost:8080
Connection: Close
Accept-Encoding: gzip
Content-Length: 377
Content-Type: application/soap+xml; charset=UTF-8; action="MySoapAction"

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope >...
讨论 (0)1
登录或注册以继续