wiki:WebServices
Last modified 6 years ago Last modified on 06/11/11 16:22:25

Web Services

We have two types of web services

  • Plain HTTP GET request: use the XQuery document() function (these are sort-of REST style, aka Plain Old XML (POX) or CGI params
  • SOAP: requires AngloSaxon XQuery extension library (or similar); can send longer queries via HTTP POST.

Plain HTTP GET Services

For most of these you can click on the link and get a simple HTML page to type queries into. Please save your queries in text files or DXbrain!

SOAP Web Services

Wiki pages and WSDL locations

Term confusion

By the way, SOAP Web Service terms overload common terms which causes some confusion. Here is a rough correspondence:

  • port: like Java Class, Perl module, etc.
  • operation: like Java Method, Perl function, etc.; may take parameters

So you call the TransformationServer with the SOAP Web Service port TransformationServer and the SOAP Web Service operation transformXML.

Documentation may also refer to the endpoint or location which is a full URL including server and path where the SOAP client POSTs its message; in this case the endpoint is http://femur.biostr.washington.edu:8080/Transformer/services/TransformationWS. You usually don't need to know the endpoint, since most clients generate it using information in the WSDL.

Example clients

These examples query a SaxonWebService; for the syntax used with the other services, see their individual wiki pages.

Example: AngloSaxon

AngloSaxon is Eider's extension to Saxon (an open source XSLT/XQuery processor) designed to call SOAP Web Services.

let $q := 
"
<results> 
{ 
$pv/patient[pnum=50]/pnum
} 
</results>
"

let $a := anglo:xquery("http://cuboid.biostr.washington.edu:8080/SaxonWebService/wsdl/XQuery.wsdl", "XQuery", "doXQuery", $q)
return 
<foo>
{$a}
</foo>

Example: Apache Axis

This example is modified from the Apache Axis documentation, save this as testClient.java:

// http://www.apache.org/licenses/LICENSE-2.0
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class testClient
{
   public static void main(String [] args) {
       try {
           String endpoint = "http://cuboid.biostr.washington.edu:8080/SaxonWebService/services/XQuery";
           Service  service = new Service();
           Call     call    = (Call) service.createCall();

           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperationName(new QName("http://soapinterop.org/", "doXQuery") );

           call.addParameter("xquery", org.apache.axis.Constants.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
           call.setReturnType(org.apache.axis.Constants.XSD_STRING);

           String xquery = ""+
             "<results> {"+ 
             "$pv/patient[pnum=50]/pnum"+ 
             "}</results>";
           String ret = (String) call.invoke(new Object[] {xquery});

           System.out.println("QUERY: \n" + xquery + "\nRESULTS: \n\n" + ret + "\n");
       } catch (Exception e) {
           System.err.println(e.toString());
       }
   }
}

On SIG Linux machines, you can compile and run testClient.java with:

CP=/usr/share/java/axis/axis.jar
CP=$CP:/usr/share/java/axis/axis-ant.jar
CP=$CP:/usr/share/java/axis/jaxrpc.jar
CP=$CP:/usr/share/java/axis/saaj.jar
CP=$CP:/usr/share/java/commons-discovery.jar
CP=$CP:/usr/share/java/commons-logging.jar
CP=$CP:/usr/share/java/log4j.jar
CP=$CP:/usr/share/java/webserviceutils.jar
CP=$CP:/usr/share/java/wsdl4j.jar
javac -cp $CP testClient.java 
java -cp $CP testClient

Example: perl SOAP::Lite

For more information see http://guide.soaplite.com, especially Access with service description (WSDL))

#!/usr/bin/perl
use SOAP::Lite;
# if you want debug output including SOAP faults add '+trace':
#use SOAP::Lite +trace;
$q = '
let $p := $pv/patient[pnum=117] 
return $p/pnum
';
print SOAP::Lite
  -> service("http://cuboid.biostr.washington.edu:8080/SaxonWebService/wsdl/XQuery.wsdl")
  -> doXQuery("$q");
print "\n";