Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » SQL Anywhere 服务器 - 编程 » HTTP Web 服务 » 使用 Web 客户端访问 Web 服务 » Web 客户端应用程序开发 » 为 Web 服务提供的变量

 

在 SOAP 封装中提供的变量

可通过 Web 客户端函数或过程的 SET SOAP 选项在 SOAP 封装中提供变量,以设置 SOAP 操作。

以下代码说明了如何在 Web 客户端函数中设置 SOAP 操作:

CREATE FUNCTION soapAddItemFunc(amount INT, item LONG VARCHAR) 
    RETURNS XML
    URL 'http://localhost:8082/itemStore'
    SET 'SOAP(OP=addItems)'
    TYPE 'SOAP:DOC';

在本示例中,addItems 是包含了 amountitem 值的 SOAP 操作,它将作为参数被传递到 soapAddItemFunc 函数。

可以运行以下示例脚本来发送请求:

SELECT soapAddItemFunc(5, 'shirt');

调用 soapAddItemFunc 函数产生类似以下示例的 SOAP 封装:



<?xml version="1.0"?>
<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:m="http://localhost:8082">
  <SOAP-ENV:Body>
    <m:addItems>
      <m:amount>5</m:amount>
      <m:item>shirt</m:item>
    </m:addItems>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

作为前一种方法的替代,可以创建自己的 SOAP 载荷,并将其发送到 HTTP 包装中的服务器。

SOAP 服务的变量必须作为标准 SOAP 请求的一部分提供。以其它方式提供的值将被忽略。

以下代码说明如何创建构建自定义 SOAP 封装的 HTTP 包装过程:



CREATE PROCEDURE addItemHttpWrapper(amount INT, item LONG VARCHAR)
RESULT(response XML)
BEGIN
    DECLARE payload XML;
    DECLARE response XML;

    SET payload =
'<?xml version="1.0"?>
<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:m="http://localhost:8082">
  <SOAP-ENV:Body>
    <m:addItems>
      <m:amount>' || amount || '</m:amount>
      <m:item>' || item || '</m:item>
    </m:addItems>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

    SET response = httpAddItemFunc( payload );
    /* process response as demonstrated in addItemFuncWrapper */
    SELECT response;
END;

以下代码说明了用于发送请求的 Web 客户端函数:

CREATE FUNCTION httpAddItemFunc(soapPayload XML)
    RETURNS XML
    URL 'http://localhost:8082/itemStore'
    TYPE 'HTTP:POST:text/xml'
    HEADER 'SOAPAction: "http://localhost:8082/addItems"';

可以运行以下示例脚本来发送请求:

CALL addItemHttpWrapper( 7, 'socks' );