You are expecting polymorphic serialization, specifically that an instance be 
serialized as its actual type rather than its declared type (in this case, the return 
type of the method).  This capability is not present in any Apache SOAP release.  That 
is at least partially because it is hard to define how this should be done in all 
possible scenarios, i.e. which interface or class to use for serialization.

The nightly builds of Apache SOAP include code that attempts to handle polymorphism.  
If you get a nightly build and add the following to your deployment descriptor, you 
may get the behavior you desire.

    <option name="PolymorphicSerialization" value="true"/>

Scott Nichol

Do not send e-mail directly to this e-mail address,
because it is filtered to accept only mail from
specific mail lists.
----- Original Message ----- 
From: "bertrand lancelot" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 24, 2004 11:48 AM
Subject: Bad object instance returned


Hi,

In a first time, I explains the context with the class and the service to
call :
public class PrimaryServices {
    public ServiceOUT service() {
        PrimaryServicesOUT serviceOUT = new PrimaryServicesOUT();
        Trace trace = new Trace();
        serviceOUT.setTrace(trace);
        serviceOUT.setServices(this);
        return serviceOUT;
    }
}

public class ServiceOUT implements java.io.Serializable {
...
}

public class PrimaryServicesOUT extends ServiceOUT {
...
}


My deployment descriptor contains all classes needed for SOAP to call the
service :

<isd:service xmlns:isd=http://xml.apache.org/xml-soap/deployment
id="urn:ServiceInvokerTest">
    <isd:provider type="java" scope="Application" methods="invoke">
        <isd:java class="com.auchan.fwk.technique.service.ServiceInvoker"
static="false"/>
    </isd:provider>

<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListene
r>
    <isd:mappings>
    <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-serviceIN" qname="x:serviceIN"
            javaType="com.auchan.fwk.technique.service.ServiceIN"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-clazz" qname="x:clazz"
            javaType="com.auchan.fwk.technique.service.Clazz"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-property" qname="x:property"
            javaType="com.auchan.fwk.technique.service.Property"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-service" qname="x:service"
            javaType="com.auchan.fwk.technique.service.Service"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-param" qname="x:param"
            javaType="com.auchan.fwk.technique.service.Param"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-serviceOUT" qname="x:serviceOUT"
            javaType="com.auchan.fwk.technique.service.ServiceOUT"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-primaryServicesOUT"
qname="x:primaryServicesOUT"
            javaType="tests.service.PrimaryServicesOUT"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-primaryServices"
qname="x:primaryServices"
            javaType="tests.service.PrimaryServices"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-trace" qname="x:trace"
            javaType="com.auchan.fwk.technique.service.Trace"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        <isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";
            xmlns:x="urn:xml-soap-service-message" qname="x:message"
            javaType="com.auchan.fwk.technique.service.Message"

java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"

xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
        </isd:mappings>
</isd:service>

After start the server and deploy the deployment file in the application, I
want to call the service with a class in client side :

public class TestSerializeServiceInvoker {
    public static void main(String[] args) throws Exception {

        URL url = new URL (args [0]);

        SOAPMappingRegistry smr = new SOAPMappingRegistry();
        BeanSerializer beanSer = new BeanSerializer();
        // Map the types.
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-serviceIN", "serviceIN"),
            ServiceIN.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-clazz", "clazz"),
            Clazz.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-property", "property"),
            Property.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-service", "service"),
            Service.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-param", "param"),
            Param.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-serviceOUT", "serviceOUT"),
            ServiceOUT.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service- primaryServicesOUT",  "primaryServicesOUT"),
            PrimaryServicesOUT.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-primaryServices", "primaryServices"),
            PrimaryServices.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-trace", "trace"),
            Trace.class, beanSer, beanSer);
        smr.mapTypes (Constants.NS_URI_SOAP_ENC, new
QName("urn:xml-soap-service-message", "message"),
            Message.class, beanSer, beanSer);

        Call call = new Call();
        call.setSOAPMappingRegistry(smr);
        call.setTargetObjectURI("urn:ServiceInvokerTest");
        call.setMethodName("invoke");
        Vector params = new Vector();
        params.addElement (new Parameter ("objectIN", ServiceIN.class,
        serviceIN, Constants.NS_URI_SOAP_ENC));
        call.setParams(params);
        // Invoke the service.
        Response resp;
        try {
            resp = call.invoke(url, "");
        } catch (SOAPException e) {
            System.err.println ("Caught SOAPException (" + e.getFaultCode()
+ "): " + e.getMessage());
            throw new RuntimeException (e);
        }

        // Check the response.
        if (!resp.generatedFault()) {
            Parameter ret = resp.getReturnValue();
            serviceOUT = (ServiceOUT)ret.getValue();
        } else {
            Fault fault = resp.getFault();
            System.err.println("Generated fault: " + fault);
        }
        System.out.println ("is a PrimaryServicesOUT instance : " +
(serviceOUT instanceof PrimaryServicesOUT ));     //==> returns false
    }
}

The service returns a PrimaryServicesOUT instance, but the response from
SOAP is a ServiceOUT instance. I think this is not correct, but I need your
advice for that. Is it a Bug ?

Best regards,
:o)

ASED - Bertrand Lancelot
[EMAIL PROTECTED]
N° interne : 5326
N° externe : 03 20 18 53 26


Reply via email to