Web service client calls can be made with stored functions or procedures. If made from a function, the return type must be of a character data type, such as CHAR, VARCHAR, or LONG VARCHAR. The body of the HTTP response is the returned value. No header information is included. Additional information about the request, including the HTTP status information, is returned by procedures. So, procedures are preferred when access to additional information is desired.
The response from a SOAP function is an XML document that contains the SOAP response.
SOAP responses are structured XML documents, so SQL Anywhere, by default, attempts to exploit this information and construct a more useful result set. Each of the top-level tags within the returned response document is extracted and used as a column name. The contents below each of these tags in the subtree is used as the row value for that column.
For example, SQL Anywhere would construct the shown data set given the following SOAP response:
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <ElizaResponse xmlns:SOAPSDK4="SoapInterop"> <Eliza>Hi, I'm Eliza. Nice to meet you.</Eliza> <ElizaResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
Eliza |
---|
Hi, I'm Eliza. Nice to meet you. |
In this example, the response document is delimited by the ElizaResponse tags that appear within the SOAP-ENV:Body tags.
Result sets have as many columns as there are top-level tags. This result set only has one column because there is only one top-level tag in the SOAP response. This single top-level tag, Eliza, becomes the name of the column.
Information within XML result sets, including SOAP responses, can be accessed using the OPENXML procedure. For more information, see openxml system procedure.
The following example uses the OPENXML procedure to extract portions of a SOAP response. This example uses a web service to expose the contents of the SYSWEBSERVICE table as a SOAP service:
CREATE SERVICE get_webservices TYPE 'SOAP' AUTHORIZATION OFF USER DBA AS SELECT * FROM SYSWEBSERVICE; |
The following web client function, which must be created in a second SQL Anywhere database, issues a call to this web service. The return value of this function is the entire SOAP response document. The response is in the .NET DataSet format because DNET is the default SOAP service format.
CREATE FUNCTION get_webservices() RETURNS LONG VARCHAR URL 'HTTP://localhost/get_webservices' TYPE 'SOAP:DOC'; |
The following statement illustrates how you can use the OPENXML procedure to extract two columns of the result set. The service_name and secure_required columns indicate which SOAP services are secure and where HTTPS is required.
SELECT * FROM openxml( get_webservices(), '//row' ) WITH ("Name" char(128) 'service_name', "Secure?" char(1) 'secure_required' ); |
This statement works by selecting the decedents of the row node. The WITH clause constructs the result set based on the two elements of interest. Assuming only the get_webservices web service exists, this function returns the following result set:
Name | Secure? |
---|---|
get_webservices | N |
For more information about the XML processing facilities available in SQL Anywhere, see Using XML in the database.
Procedures of other types return all the information about a response in a two-column result set. This result set includes the response status, header information and body. The first column, is named Attribute and the second is named Value. Both are of data type LONG VARCHAR.
The result set has one row for each of the response header fields, and a row for the HTTP status line (Status attribute) and a row for the response body (Body attribute).
The following example represents a typical response:
Attribute | Value |
---|---|
Status | HTTP /1.0 200 OK |
Body | <!DOCTYPE HTML ... ><HTML> ... </HTML> |
Content-Type | text/html |
Server | GWS/2.1 |
Content-Length | 2234 |
Date | Mon, 18 Oct 2004, 16:00:00 GMT |
For more information, see Accessing variables in result sets.
Working with data types (SOAP only)
Working with structured data types (SOAP only)
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |