This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

This gadget allows a gadget author to invoke a SOAP Web Service, without cross-domain restrictions from the gadget's JavaScript. The SOAP Web service needs to be started before deploying such a gadget in the Gadget Server.

A SOAPRequest gadget code snippet is given below.

<?xml version="1.0" encoding="UTF-8" ?>  
     <Module>  
     <ModulePrefs title="hello world example">  
     <Require feature="wso2.soap"/>
     </ModulePrefs>  
     <Content type="html">  
     <![CDATA[
     <div id=response-disp></div>
  
    <script>
      function doSOAPCall(){
       var endpoint = "http://localhost:9763/services/HelloService";
       var payload = ' <p:greet xmlns:p="http://www.wso2.org/types"> <name>SOAP Request </name> </p:greet>';
       var operation = "urn:greet";
       document.getElementById("response-disp").innerHTML = wso2.io.makeSOAPRequest(endpoint, operation, payload);
      }
     gadgets.util.registerOnLoadHandler(doSOAPCall);
   </script>  
    ]]>  
   </Content>  
   </Module>

Notable Syntax in the Code

  • Gadgets are specified in XML. The first line is the standard way to start an XML file. This must be the first line in the file.
  • The <Module> tag indicates that this XML file contains a gadget.
  • The <ModulePrefs> tag contains information about the gadget such as its title, description, author, and other optional features.
  • The <Require feature="wso2.soap"/> is used to inform the gadget container that this gadget needs an extra feature to invoke function. This type of features are pre-written Javascript code, which is loaded to the gadget on demand by the gadget container. In this code, it is required to import the feature 'wso2.soap', inorder to make a SOAP request from the gadget.
  • The line <Content type="html"> indicates that the gadget's content type is HTML.
  • <![CDATA[ ...insert HTML here... ]]> is used to enclose HTML when a gadget's content type is html. It tells the gadget parser that the text within the CDATA section should not be treated as XML. The CDATA section typically contains HTML and JavaScript.
  • JavaScript 'doSOAPCall' function defines three parameters required to invoke makeSOAPRequest function such as endpoint (Url of SOAP service ), payload and operation. Then by using "wso2.io.makeSOAPRequest(endpoint, operation, payload)" method, the SOAP service end point is invoked. Finally the response from the invoked SOAP service end point is displayed inside the gadget.
  • </Content> signifies the end of the Content section.
  • </Module> signifies the end of the gadget definition.
  • No labels