Example: Web Service Client Comparison


This section uses a simple stock quote Web service to illustrate how you might build an XQuery Web service client using both the ddtek:wscall and ddtek:http-* functions.

Using HTTP Functions

Here is how you might use DataDirect XQuery HTTP functions to build an XQuery Web service client application. You start by declaring three variables – $host, $payload, and $options.

The $host variable is used to specify the endpoint for the Web service – specifically, the URI of the Web Service Description Language (WSDL) that defines the getQuotes operation made available by this Web service:

declare variable
		$host := "http://examples.xquery.com/stock-quotes/WSDL"; 

The $payload variable is used to specify the SOAP message that is submitted to the Web service by the XQuery Web service client. In this example, the SOAP message contains the ticker value (here, it is PRGS).

declare variable $payload :=
<SOAP-ENV:Envelope  
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <dd:getQuotes xmlns:dd="http://www.datadirect.com">
            <dd:tickers>PRGS</dd:tickers>
        </dd:getQuotes>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>; 

The $options variable is used to specify the name of the SOAP action (getQuotes.xquery) that is performed by the SOAP operations (getQuotes) exposed by the XQuery Web service.

declare variable $options := 
  <request> 
       <request-header> 
        <header name="SOAPAction" value="getQuotes.xquery"/> 
    </request-header> 
  </request>; 

Once the $host, $payload, and $options variables is defined, you can use them to invoke the ddtek:http-post function, as shown here:

let $http-response := ddtek:http-post($host, $payload, $options)/response 
return 
  if($http-response/@status-code eq '200') then 
   $http-response/response-body/* 
  else $http-response 

Using ddtek:wscall

Here is the same application written using ddtek:wscall:

declare variable $host :=  
<ddtek:location  
    address="http://examples.xquery.com/stock-quotes//WSDL" 
    soapaction="getQuotes.xquery"/>; 
 
declare variable $payload :=  
<ddtek:getQuotes> 
    <ddtek:tickers>PRGS</ddtek:tickers> 
</ddtek:getQuotes>; 
 
 
ddtek:wscall($host, $payload) 

The declarations of the $host and $payload variables using the ddtek:wscall function are similar to those using ddtek:http-post, with a few differences: