Make SOAP based Web service calls with Spry

I decided to try to use Spry to make a SOAP based web service call using a ColdFusion CFC for the web service.

Spry 1.1 allows developers to make GET and POST method calls for DataSets. Here is an example I wrote that calls one of my quote web services;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Call Webservice</title>
<script language="JavaScript" type="text/javascript" src="spry/includes/xpath.js"></script>
<script language="JavaScript" type="text/javascript" src="spry/includes/SpryData.js"></script>
</head>

<body>
<script>
var dsData = new Spry.Data.XMLDataSet("http://www.fekke.com/com/SpockWS.cfc", "/soapenv:Envelope/soapenv:Body/ns1:getQuoteResponse/getQuoteReturn", { method: "POST", postData: '<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://com" xmlns:intf="http://com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ><SOAP-ENV:Body><mns:getQuote xmlns:mns="http://com" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"></mns:getQuote></SOAP-ENV:Body></SOAP-ENV:Envelope>', headers: { "Content-Type": "text/xml; charset=utf-8", "SOAPAction": "http://localhost:8300/com/SpockWS/getQuote" } , useCache: false });
dsData.startLoadInterval(10000);
</script>
<div id="Specials_DIV" spry:region="dsData">
Episode: {episode} <br />
<em>{quote}</em><br />
Stardate: {stardate}
</div>
<input type="button" name="Do something" value="Get Quote" onclick="dsData.loadData();" />
</body>
</html>

The trick to getting this to work is setting the header attribute for the XMLDataSet method with a SOAPAction method.

Comments
Pablo's Gravatar I´m using spry to get data from a servlet but i get an error, ¿Can you help me with this?

I´m trying to get an XML with this line:
var dsTx = new Spry.Data.XMLDataSet("http://140.10.33.20:8080/struts-ajax/xml.do", "/transacciones/tx"

But I get tis error message:
Spry.Data.XMLDataSet.setDataFromDoc() failed to create dataSet ''for 'transacciones/tx' - http://172.16.48.121:8080/struts-ajax/xml.do

Thanks in advance, and sorry about my english!!!
# Posted By Pablo | 7/5/06 12:49 PM
David Fekke's Gravatar Paquista,

I just tried to call that servlet, and nothing happened. You might want to try creating a static XML file first to be called from that server.

By the way, your English is fine. I grew up in the U.S., and I don't speak english good. . . well.

Thank you,
David Fekke.
# Posted By David Fekke | 7/5/06 2:57 PM
Scion Of Faith's Gravatar Sheesh ty and search for spry web service call and all i get fekke.com ...... with the new version out is this still the only way to do this? I need to pass params to a webservice and this example is only a call.
# Posted By Scion Of Faith | 8/24/06 11:58 AM
David Fekke's Gravatar John,

You can pass the params in the XML that is being sent to the web service. You can see what the XML needs to look like by going to soapclient.com. The will need the WSDL file, but this site will show what the request and response should look like.

David
# Posted By David Fekke | 8/24/06 1:24 PM
Guest heer's Gravatar You can pass the params in the XML that is being sent to the web service. You can see what the XML needs to look like by going to soapclient.com. The will need the WSDL file, but this site will show what the request and response should look like. [url=http://www.tupbebegim.org ]tüp bebek[/url]
[url=http://www.sacekimmerkezi.org ]saç ekimi[/url]
[url=http://www.ankara-evnakliyat.org ]ankara nakliyat[/url]
[url=http://www.uluslararasi-nakliyat.org ]ankara nakliyat[/url]
[url=http://www.estetik-merkezleri.com ]estetik[/url]
[url=http://www.ankara-nakliyat.name.tr ]ankara nakliyat[/url]
[url=http://www.ankara-nakliyatcim.org ]ankara nakliyat[/url]
[url=http://www.ankara-nakliyeci.net ]ankara nakliyat[/url]
[url=http://www.estetik-merkezleri.com ]burun estetigi[/url]
# Posted By Guest heer | 6/10/08 5:35 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.6.001.