RPC Response Encoding Styles

RPC Response Encoding Styles

Since the SOAP specification does not describe how to specify what encodingStyle to use for the response to an RPC request, Apache SOAP's RPCJavaProvider employs a simple algorithm to choose an appropriate encodingStyle.

First, the method call element is examined for an encodingStyle attribute. If there is no encodingStyle attribute on the call element, each parameter element is then examined in document order for encodingStyle attributes. The value specified in the first encodingStyle attribute encountered is used. If none of the parameter elements have an encodingStyle attribute, SOAP Encoding (section 5 of the SOAP specification) is used.

Put another way, if the call element specifies an encodingStyle, it is used for the response. If the call element does not specify an encodingStyle, the first parameter element-specified encodingStyle is used. If none of the parameter elements specify an encodingStyle, or if there are no parameter elements, SOAP Encoding is used by default.

Let's work through a couple of examples by answering several common questions:

Question: How do I tell an Apache SOAP server (using the RPCJavaProvider; i.e. provider type="java" in the deployment descriptor) to use literalXML encodingStyle for the response to my RPC request?

Answer: Simply set the desired response encodingStyle as the encodingStyle of the call object:

    // Build the call.
    Call call = new Call();

    ... configure the call (i.e. targetObjectURI, methodName,
        typeMappings, etc.) ...

    call.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);

    ... make the invocation and cast the value carried in the return
        parameter to an org.w3c.dom.Element ...
    

Note: See samples.addressbook.GetAllListings for a complete example.

Question: How do I tell an Apache SOAP server (using the RPCJavaProvider; i.e. provider type="java" in the deployment descriptor) to use literalXML encodingStyle for the response to my RPC request, and still send parameters using SOAP encoding?

Answer: Set the desired response encodingStyle as the encodingStyle of the call object, and set each parameter's encodingStyle individually:

    // Build the call.
    Call call = new Call();

    ... configure the call (i.e. targetObjectURI, methodName,
        typeMappings, etc.) ...

    call.setEncodingStyleURI(Constants.NS_URI_LITERAL_XML);
    Vector params = new Vector();
    // A simple type...
    params.addElement(new Parameter("quantity",
                                    int.class,
                                    new Integer(123),
                                    Constants.NS_URI_SOAP_ENC));
    // A complex (user-defined) type...
    params.addElement(new Parameter("address",
                                    Address.class,
                                    addr,
                                    Constants.NS_URI_SOAP_ENC));
    call.setParams(params);

    ... make the invocation and cast the value carried in the return
        parameter to an org.w3c.dom.Element ...
    

Authors: Matthew J. Duftler and Dirck Hecking