Usage examples for the IBM® SOAP library

The SOAP service can be instantiated using the service description from either a local or a remote file. The service description can be either in a .smd or a .wsdl file format. See the following usage example:

	
<div dojoType="ibm_soap.widget.SoapService" id="bnpriceService"
	url="./bnpriceGenerated.smd">

<div dojoType="ibm_soap.widget.SoapService" id="amazonCommerceService"
	url="./AWSECommerceService.wsdl">

You must provide the location of the service description as the URL. After the widgets are parsed and instantiated, the service is ready for use. Typically, you must begin with a service that provides a service description as a .wsdl file. You can use the provided WsdlParser to convert to .smd format. See the following example usage:

var parser=new ibm_soap.util.WsdlParser();
parser.parse("./serviceDescription.wsdl"); var smdString = parser.smdString;

When you parse a WSDL format description, you can access the results by using the smdString or the smdObject member of the parser. Consider the following items when converting the service description:

To call a method described by the service, you need to know the method name and the structure of the parameters expected by the method. For instance, see the example of how to call the ItemLookUp method for the Amazon service. First, build the parameter list:

		// Assume accessKeyId holds the AccessKeyId required by Amazon.
		var amazonServiceParms = new dojox.wire.ml.XmlElement("ItemLookUpRequest");
		amazonServiceParms.setPropertyValue("AWSAccessKeyId",accessKeyId);
		amazonServiceParms.setPropertyValue("ItemId",isbn);

Set the required properties by calling the setPropertyValue method. The variable, isbn, stores the ISBN that is to be searched. Next, invoke the service method using the service member of the widget as the following example:

	var deferred = amazonCommerceService.service.ItemLookup(amazonServiceParms)

The call returns an object of type dojo.Deferred that contains the BODY node of the returned content. You can use simple Document Object Model (DOM) manipulation to access the result. See the following example of accessing the results from the returned data:

deferred.addCallback(function(results){
			var title = results.getElementsByTagName("Title")[0].firstChild.nodeValue;
			var author = results.getElementsByTagName("Author")[0].firstChild.nodeValue;
			var publisher = results.getElementsByTagName("Manufacturer")[0].firstChild.nodeValue;
			var resultNode = dojo.byId("details");
			resultNode.innerHTML = "<br><b>Title:</b>"  + title
					+ "<br><b>Author:</b>" + author
					+ "<br><b>Publisher:</b>" + publisher;
		});

Proxy requirement

Because of cross-domain XMLHttpRequest (XHR) restrictions, you might need to use a proxy to reach the service endpoints that are defined in the service description. You must modify the service endpoints to incorporate the proxy. The modified version of the Barnes and Noble price service might resemble the following example:


<app name>/ajaxProxy/www.abundanttech.com/WebServices/bnprice/bnprice.asmx.

After you change the service endpoint URLs in the service description file, you might also need to perform additional configuration for the proxy to forward requests to the external server. Refer to the documentation provided with the proxy that you are using for more information.



Terms of Use | Feedback