>Home>XQuery Solutions>Web Services
The DataDirect XQuery® XQueryWebService Framework
XQueryWebService is a framework that allows you to expose an XQuery as a Web service. XQueryWebService is a Java servlet tested on numerous Java servlet containers like Apache Tomcat, JBoss, IBM WebSphere, and BEA WebLogic, the XQueryWebService framework simplifies the design and implementation of Web service applications.
Each XQuery exposed as a Web service provides a single operation; this operation is expressed in the query body through a function that takes the name of the XQuery file without the extension. For example, the file
emp.xquery provides the
emp operation. Parameters (external variables) expressed in the XQuery, if any, are reflected in the operation’s prototype.
Get hands-on experience running XQuery Web service applications developed using the XQueryWebService framework on a live application server. Run finished applications like the Photo Search Demonstration, test Web service operations exposed by the XQueryWebService framework, or just explore the WSDL used to describe Web service operations that query relational data sources. Take a look here to get going right away! If you'd rather learn more about some of our XQueryWebService examples first, go here.
XQueryWebService Framework Architecture Overview
Let's take a look at the XQueryWebService framework architecture before getting into more of the details.
A high-level illustration of the XQueryWebService framework architecture shows all the pieces at work to expose an XQuery as a Web service:
(click to enlarge)
To start, an HTTP request is submitted to a Web server — a Tomcat Web Server in this case. The URL used to invoke the Web service takes the following form:
- http://examples.xquery.com/employee-lookup/emp.xquery is the location of the XQuery Web service. The Web service was created by saving an XQuery to the /employee-lookup folder where the Tomcat Web Server is running.
- id=A-C71970F is a parameter passed to the XQuery. The variable that takes this parameter is defined in
declare variable $id as xs:string external;
for $employee in collection("employee")/employee
where $employee/emp_id = $id
The query body is just a single FLWOR (For each, Let, Where, Order by, Return) expression.
When the XQuery processing is finished, it returns a value using HTTP response, as shown in the following illustration:
(click to enlarge)
Most of the work performed by the Web service takes place in the DataDirect XQueryWebService servlet, a close-up of which is shown here:
The browser (or an application) submits the Web service request using SOAP or HTTP GET for the XQuery stored on the Web server. Next, DataDirect XQuery unpacks the Web service request and binds its parameters, if any, to the XQuery. In our example, the parameter passed with the Web service request is an ID. The XQuery is then executed and its result (an XML document) is returned to the client.
(See XQueryWebService Interfaces to learn more about binding support for the XQueryWebService framework.)
Learn about the role of the Web Service Description Language (WSDL) in building Web service applications using the XQueryWebService framework.