可通过 Web 客户端函数或过程的 SET SOAP 选项在 SOAP 封装中提供变量,以设置 SOAP 操作。
以下代码说明了如何在 Web 客户端函数中设置 SOAP 操作:
CREATE OR REPLACE FUNCTION soapAddItemFunction("amount" int, item long varchar) RETURNS XML URL 'http://localhost/store' SET 'SOAP(OP=addItems)' TYPE 'SOAP:DOC'; |
在本示例中,addItems 是包含了 amount 和 item 值的 SOAP 操作,它将作为参数被传递到 soapAddItemFunction 函数。
可以运行以下示例脚本来发送请求:
SELECT soapAddItemFunction(5, 'shirt'); |
调用 soapAddItemFunction 函数产生类似以下示例的 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"> <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 or replace 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"> <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 = httpAddItemFunction( payload ); /* process response as demonstrated in addItemFunctionWrapper */ select response; end |
以下代码说明了用于发送请求的 Web 客户端函数:
create or replace function httpAddItemFunction("soapPayload" xml ) returns XML url 'http://localhost/store' type 'HTTP:POST:text/xml' header 'SOAPAction: "http://localhost/addItems"'; |
可以运行以下示例脚本来发送请求:
call addItemHttpWrapper( 5, 'shirt' ); |
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |