在本课中,您将设置用于发送 SOAP 请求和接收 SOAP 响应的 Web 客户端。本课假设您已经按照前面课程设置了 Web 服务器数据库。有关本课所述的设置数据库服务器以接收 Web 客户端 SOAP 请求的信息,请参见第 1 课:设置用于接收 SOAP 请求和发送 SOAP 响应的 Web 服务器数据库。
本课中包含对 localhost 的引用。如果 Web 客户端与服务器数据库运行在不同的计算机上,则使用第 1 课中服务器数据库的 IP 地址,而不要用 localhost。
运行以下命令创建 SQL Anywhere 数据库:
dbinit ftc_client |
使用以下命令启动个人数据库客户端:
dbsrv12 ftc_client.db |
使用以下命令在 Interactive SQL 中连接数据库:
dbisql -c "UID=DBA;PWD=sql;SERVER=ftc_client" |
创建新的存储过程以向 DISH 服务发送 SOAP 请求。
在 Interactive SQL 中运行以下 SQL 脚本:
CREATE SERVICE soap_endpoint TYPE 'DISH' AUTHORIZATION OFF SECURE OFF USER DBA; CREATE PROCEDURE FtoC( temperature FLOAT ) URL 'http://localhost:8082/soap_endpoint' SET 'SOAP(OP=FtoCService)' TYPE 'SOAP:DOC'; |
URL 子句中的 http://localhost:8082/soap_endpoint 字符串表示数据库服务器运行在 localhost 上且监听 8082 端口。需要的 DISH Web 服务名为 soap_endpoint,它作为 SOAP 端点。
创建构建 SOAP 标头的包装过程,将它传递给 FtoC 过程,并处理服务器响应。
在 Interactive SQL 中运行以下 SQL 脚本:
CREATE PROCEDURE FahrenheitToCelsius( temperature FLOAT ) BEGIN DECLARE io_header LONG VARCHAR; DECLARE in_header LONG VARCHAR; DECLARE result LONG VARCHAR; DECLARE err INTEGER; DECLARE crsr CURSOR FOR CALL FtoC( temperature, io_header, in_header ); SET io_header = '<Authentication xmlns="SecretAgent" ' || 'mustUnderstand="1">' || '<userName alias="99">' || '<first>Susan</first><last>Hilton</last>' || '</userName>' || '</Authentication>'; SET in_header = '<Session xmlns="SomeSession">' || '123456789' || '</Session>'; MESSAGE 'send, soapheader=' || io_header || in_header; OPEN crsr; FETCH crsr INTO result, err; CLOSE crsr; MESSAGE 'receive, soapheader=' || io_header; SELECT temperature, Celsius FROM OPENXML(result, '//tns:answer', 1, result) WITH ("Celsius" FLOAT 'text()'); END; |
第一个 SET 语句指定 SOAP 标头的以下 XML 表示,以向 Web 服务器通知用户证书:
<Authentication xmlns="SecretAgent" mustUnderstand="1"> <userName alias="99"> <first>Susan</first> <last>Hilton</last> </userName></Authentication> |
第二个 SET 语句设置 SOAP 标头库的以下 XML 表示,以跟踪客户端会话 ID:
<Session xmlns="SomeSession">123456789</Session> |
OPEN 语句向 Web 服务过程传递 SOAP 请求的以下 XML 表示:
<Authentication xmlns="SecretAgent" alias="99" mustUnderstand="1"> <first>Susan</first> <last>Hilton</last> </Authentication> |
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |