SOAPClient Documentation

Objects

SOAPClient

This static class exposes two methods, one object and three properties

Note: As you may already know, browsers security restrictions will prevent you from requesting resources from other domains then where your JavaScript code is running, this is called a Cross-Domain Violation. In order to bypass this security restriction safely, you will need to write a single server-side executable (i.e. asp, jsp, php or servlet) file that will work as a proxy between your domain and remote domain you trying to talk to.

In order to create a universal proxy that will work with many different web services, there must be a way to let your proxy know about a web service URL it should talk to. The only way of doing it w/o corrupting SOAP Envelope data, is by using custom HTTP headers. SOAPClient uses this technique and allows you to set SOAPServer header variable that can be read by your proxy code and redirect requests appropriately. An example of ASP.NET Proxy will be provided in examples section.

  • Properties
    • Proxy (String) - Local Proxy file that redirects your soap request to a web-service (default: "")
    • SOAPServer (String) - Absolute path to a web-service you want to communicate with.
      This variable is created to accomplish a goal of universal proxy that can work with any web service. By setting this value, a new header variable will be created "SOAPServer" and passed to your proxy. With that in mind, you can write your proxy code to read this variable and use it as the redirect URI.
    • ContentType (String) - well, it's a content type :) (default: "text/xml")
    • CharSet (String) - Character Set (default: "utf-8")
    • ResponseXML (XMLDocument) - Returns an XMLDocument of the response envelope (default: null)
    • ResponseText (String) - Returns a string XML of the response envelope (default: "")
    • Status(Integer) - Returns a response status code returned from the server (i.e. 200) (default: 0)
  • Object
    • .Namespace(name, uri) - Used to create new namespace object (ex.: new SOAPClient.Namespace("ns","http://....");)
      • name (String) - Namespace extension name
      • uri (String) - Namespace URI
  • Methods
    • SendRequest(soapReq, callback) - This is the method that invokes a SOAP Action and passes to it a SOAPRequest object
      • soapReq (SOAPRequest) - this is an instance of a SOAPRequest object that encapsulates all data that needs to be sent to web-service and SOAPAction keyword.
      • callback (function(data)) - Reference to a call-back function. Call-back also passes a data object that is JSON equivalent of SOAP response envelope
        • data (JSON) - a result of xmlObjectifier transformation, and object that contains Head and Body elements of SOAP response xml.
    • ToXML(soapObj) - Serializes SOAPObject to an XML string that is acceptible by SOAP protocol. This is a recursive function that processess all child elements as well.
      • soapObj (SOAPObject) - Instance of a SOAPObject populated with data
  • BETA Methods
    • SetHTTPHeader(name, value) - Sets an HTTP header that will be sent with SOAP request
      • name (String) - HTTP header name (1 - 20 characters)
      • value (Object) - HTTP header value

SOAPRequest

Instantiatable class that encapsulates all components that go into SOAP Request envelope

  • Properties
    • Action (String) - This is where you would set a SOAPAction header value
  • Methods
    • constructor(action, bodyObj) - when you create new SOAPRequest object you would pass two arguments
      • action (String) - Sets Action property to the correct SOAPAction header value
      • bodyObj (SOAPObject) - adds a request object to the soapenv:Body section
    • addNamespace(ns, uri) - Appends a namespace to a SOAP Envelope
      • ns (String) - Namespace name
      • uri (String) - Namespace uri
    • addHeader(headerObj) - appends SOAP element to a soapenv:Header section
      • headerObj (SOAPObject) - an object to be appended to the header (used mostly for authentication/credentials passing)
    • addBody(bodyObj) - appends SOAP element to soapenv:Body section (if more then one). Can be used instead of passing body object at constructor level.
      • bodyObj (SOAPObject) - adds a request object to the soapenv:Body section
    • toString() - returns an XML String of entire soapenv:Envelope with all it's contents

SOAPObject

Instantiatable class, that represents a basic SOAP element

  • Properties
    • typeOf (String) - "read-only" property that returns string "SOAPObject". Used for object validation only. Used during SOAPClient.ToXML serialization to avoid parsing of unsupported object type.
      • ns (String | Object) - This is a namespace property that can be set to either a string URI or to an instance of SOAPClient.Namespace object. If it's set to a String then the output will only contain "xmlns=uri" attribute. If set to an object then namespace name will be prepended to the tag and all attributes.

        Ex 1 - Setting ns property to a String:
        var newNode = new SOAPObject("new_node");
            newNode.ns = "http://myuri.com";

        Result: <new_node xmlns="http://myuri.com">

        Ex 2 - Setting ns property to an object
        var newNode = new SOAPObject("new_node");
            newNode.ns = new SOAPCLient.Namespace("ns", "http://myuri.com");
            newNode.attr("type","test");

        Result: <ns:new_node xmlns:ns="http://myuri.com" ns:type="test">

    • name (String) - Set/Get name of the node
    • attributes (Array) - This array contains name/value pair objects "{name: name, value: value}" for each attribute of the element
    • children (Array) - This array contains nested SOAPObject instances, that are children of this object
    • value (String) - contains node value.
  • Methods
    • attr(name, value) - appends an attribute to attributes array. Returns a reference to the parent SOAPObject (i.e. this)
      • name (String) - name of an attribute
      • value (String) - value of an attribute
    • val(value) - Sets a value of the node. Returns a reference to the parent SOAPObject (i.e. this)
      • value(String) - String value of the node. Note: There is no escape validation here, so you can effectively insert a sub node this way
    • appendChild(soapObj) - Append a child node element. Returns a reference to an appended object (i.e. soapObj)
      • soapObj (SOAPObject) - instance of SOAPObject that represents a nested node
    • hasChildren() - Returns a Boolean reflecting presence of child objects
    • toString() - Returns an XML String of itself and all nested objects
Terracoder.com © 2007 | All Rights reserved
xmlObjectifier by terracoder.com is licensed under a Creative Commons Attribution-No Derivative Works 3.0 United States License. Based on a work at terracoder.com.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses.
Creative Commons License
Job Opportunities