Revision 129074 of SOAP in Gecko-based Browsers

  • Revision slug: SOAP_in_Gecko-based_Browsers
  • Revision title: SOAP in Gecko-based Browsers
  • Revision id: 129074
  • Created:
  • Creator: JML
  • Is current revision? No
  • Comment

Revision Content

Transfering from devedge page
http://devedge-temp.mozilla.org/viewsource/2003/soap/01/index_en.html

Work in progress

This article shows how to access web services using the SOAP and JavaScript capabilities available in recent Gecko-based browsers.

Introduction

Simple Object Access Protocol (SOAP) is the basis on which web services are built. It is an XML-based protocol used to communicate and interoperate with web services. With Mozilla 1.0 (upon which Netscape 7.0x is built), it is now possible for the browser to directly communicate with web services using its low-level SOAP implementation through JavaScript.

Gecko's JavaScript interface for establishing SOAP calls is a low-level API which requires one to build the SOAP envelope using several SOAP-specific JavaScript objects. This article will cover the basic SOAP operations, for a more detailed look at the low-level SOAP API in Gecko click here.(Find the equivalent to "soap scripts in mozilla")

Using JavaScript to talk to web services is subject to the same security policies as other scripts in terms of cross domain access. Therefore, accessing web services on a server other than the one where the JavaScript lives will violate the cross-domain policy. This article will show how to temporarily circumvent this for testing purposes.

Setting Up a SOAP Call

The most basic object is SOAPCall, which is used to initiate and invoke a SOAP call.

Figure 1 : Basic setup and invocation of a SOAP Call

var mySOAPCall = new SOAPCall();
mySOAPCall.transportURI = "http-based service URI"
mySOAPCall.encode(0, "method name ", "target object namespaceURI ", 0, null, SOAPParameter array.length, SOAPParameter array);
var response = mySOAPCall.invoke();

A SOAPCall object has a member called transportURI, which is the URI of the location where it should send the SOAP call to. The encode method requires the name of the method to call at the web service, its namespaceURI, the amount of SOAPParameters passed in, and an array of SOAPParameters which contains all the parameters. All these parameters can be found in the WSDL file for the web service, which is discussed in the Example section.

SOAP parameters are created using the SOAPParameter object. They are name/value pairs that are passed to the web service.

Figure 2 : Creating a SOAP parameter

var param = new SOAPParameter();
param.name = "translationmode";
param.value = "en_fr";


Handling a Response

Once invoke is called, Gecko generates the SOAP envelope and sends it to the URI specified. Since the request is synchronous, the response is the return value of invoke.

Figure 3 : Handling the response of a SOAP call

 var returnObject = mySOAPCall.invoke();

if(returnObject.fault){
  alert("An error occured: " + returnObject.fault.faultString);
} else {
  var response = new Array();
  response = returnObject.getParameters(false, {});
  alert("Return value: " + response[0].value);
}

The return value of invoke is stored and checked for a fault member. If it exists, an error occurred at the web service, and the error message is stored in fault.faultString. If fault doesn't exist, we call the getParameters function on the returned object to retrieve the returned SOAPParameters.

Example

Tracking the Soap Envelope

Resources

Revision Source

<pre>Transfering from devedge page
http://devedge-temp.mozilla.org/viewsource/2003/soap/01/index_en.html

Work in progress
</pre>
<p>This article shows how to access web services using the SOAP and JavaScript capabilities available in recent Gecko-based browsers.</p>
<h2 name="Introduction"><b>Introduction</b></h2>
<p>Simple Object Access Protocol (SOAP) is the basis on which web services are built. It is an XML-based protocol used to communicate and interoperate with web services. With Mozilla 1.0 (upon which Netscape 7.0x is built), it is now possible for the browser to directly communicate with web services using its low-level SOAP implementation through JavaScript.</p>
<p>Gecko's JavaScript interface for establishing SOAP calls is a low-level API which requires one to build the SOAP envelope using several SOAP-specific JavaScript objects. This article will cover the basic SOAP operations, for a more detailed look at the low-level SOAP API in Gecko click here.(Find the equivalent to "soap scripts in mozilla")</p>
<p>Using JavaScript to talk to web services is subject to the same security policies as other scripts in terms of cross domain access. Therefore, accessing web services on a server other than the one where the JavaScript lives will violate the cross-domain policy. This article will show how to temporarily circumvent this for testing purposes. </p>
<h2 name="Setting_Up_a_SOAP_Call"><b>Setting Up a SOAP Call</b></h2>
<p>The most basic object is SOAPCall, which is used to initiate and invoke a SOAP call.</p>
<p>Figure 1 : Basic setup and invocation of a SOAP Call
</p>
<pre>var mySOAPCall = new SOAPCall();
mySOAPCall.transportURI = "http-based service URI"
mySOAPCall.encode(0, "method name ", "target object namespaceURI ", 0, null, SOAPParameter array.length, SOAPParameter array);
var response = mySOAPCall.invoke();
</pre>
<p> A SOAPCall object has a member called transportURI, which is the URI of the location where it should send the SOAP call to. The encode method requires the name of the method to call at the web service, its namespaceURI, the amount of SOAPParameters passed in, and an array of SOAPParameters which contains all the parameters. All these parameters can be found in the WSDL file for the web service, which is discussed in the Example section.</p>
<p>
SOAP parameters are created using the SOAPParameter object. They are name/value pairs that are passed to the web service. </p>
<p>Figure 2 : Creating a SOAP parameter
</p>
<pre>var param = new SOAPParameter();
param.name = "translationmode";
param.value = "en_fr";

</pre>
<p><br>
</p>
<h2 name="Handling_a_Response"><b>Handling a Response</b></h2>
<p> Once invoke is called, Gecko generates the SOAP envelope and sends it to the URI specified. Since the request is synchronous, the response is the return value of invoke.  </p>
<p>Figure 3 : Handling the response of a SOAP call</p>
<pre> var returnObject = mySOAPCall.invoke();

if(returnObject.fault){
  alert("An error occured: " + returnObject.fault.faultString);
} else {
  var response = new Array();
  response = returnObject.getParameters(false, {});
  alert("Return value: " + response[0].value);
}
</pre>
<p>
 The return value of invoke is stored and checked for a fault member. If it exists, an error occurred at the web service, and the error message is stored in fault.faultString. If fault doesn't exist, we call the getParameters function on the returned object to retrieve the returned SOAPParameters.
</p>
<h2 name="Example"><b>Example</b></h2>
<p>  </p>
<h2 name="Tracking_the_Soap_Envelope"><b>Tracking the Soap Envelope</b></h2>
<p>  </p>
<h2 name="Resources"><b>Resources</b></h2>
<p>  </p>
Revert to this revision