Hi Oliver,
It seems that at least on the JAX-RPC list, this question usually just gets
one a lecture on interfaces having no constructors and thus being
non-serializable; quite puzzling.
Well, I had to expose services whose interfaces rely heavily on abstract
data types, so (finally) I have something similar working with alpha3 (it
may not be very orthodox as I am quite new at this -- I expect that the Axis
developers will be of more help). I apologise for the length of this
message, but if it helps...
// some (bogus) illustrative code. The service methods are of the kind:
public Book find(BookId id) throws MyException;
// concrete type to be returned:
public class Novel implements Book {...}
I ran Java2Wsdl on the service class and got mostly OK WSDL, except that I
had to tweak the <schema> to show the derived object (see below), so you may
want to customize the generation of WSDL (I needed .NET to read this WSDL --
reading a .XSD file was not working -- and generate C# proxy classes that
reflected my java side hierarchy, with a Book interface or abstract class at
the top of the hierarchy).
The correct type mappings need to be registered, either in the .wsdd file
as:
<beanMapping qname="ns2:Book" languageSpecificType="java:my.pkg.Book"
xmlns:ns2="urn:SomeUniqueThing"/>
<beanMapping qname="ns2:Novel" languageSpecificType="java:my.pkg.Novel"
xmlns:ns2="urn:SomeUniqueThing"/>
<beanMapping qname="ns6:BookId" languageSpecificType="java:my.pkg.BookId"
xmlns:ns6="urn:SomeUniqueThing"/>
or, if you have too many concrete types that are obtained via some factory
reg/lookup mechanism (as I do), you can register a custom type mapping
handler that will insert the mapping for Novel etc. into the registry:
<handler type="java:test.soap.MyTypeMappingHandler"/>
which does:
public class MyTypeMappingHandler extends BasicHandler {
public void invoke(MessageContext msgContext) throws
org.apache.axis.AxisFault {
TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry();
try {
BeanSerializer ser = new BeanSerializer();
DeserializerFactory deser = ser.getFactory();
///////// THESE WOULD NOT BE HARDCODED BUT WOULD COME FROM
YOUR FACTORY
tmr.addSerializer(my.pkg.Novel.class, new
QName("urn:SomeUniqueThing","Novel"), ser);
tmr.addDeserializerFactory(new
QName("urn:SomeUniqueThing","Novel"), my.pkg.Novel.class, deser);
}
catch (Exception e) {... } }
<schema targetNamespace="urn:SomeUniqueThing"
xmlns:intf="urn:SomeUniqueThing" xmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="BookId">
<sequence>
<element name="id" type="string"/>
</sequence>
</complexType>
<element name="BookId" type="intf:BookId" nillable="true"/>
<complexType name="Book" abstract="true">
<sequence>
<element name="bookId" type="intf:BookId"/>
</sequence>
</complexType>
<complexType name="Novel">
<complexContent>
<extension base="intf:Book">
<sequence>
<element name="author"
type="string"/>
<element name="title"
type="string"/>
<element name="version" type="int"
default="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="Book" type="intf:Book" nillable="true"/>
<element name="Novel" type="intf:Novel" nillable="true"/>
<schema/>
....
<message name="findRequest">
<part name="arg0" type="intf:BookId"/>
</message>
<message name="findResponse">
<part name="findResult" type="intf:Book"/>
</message>
...
.NET generated code:
<upon calling the service, in my client code I receive a C# Novel object>
...
/// <remarks/>
[System.Xml.Serialization.SoapTypeAttribute("Book", "urn:SomeUniqueThing")]
[System.Xml.Serialization.SoapIncludeAttribute(typeof(Novel))]
public abstract class Book {
/// <remarks/>
public BookId bookId;
}
/// <remarks/>
[System.Xml.Serialization.SoapTypeAttribute("Novel", "urn:SomeUniqueThing")]
public class Novel : Book {
/// <remarks/>
public string author;
/// <remarks/>
public string title;
/// <remarks/>
public int version;
}
...
-----Original Message-----
From: Oliver Suciu [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 07, 2002 2:51 AM
To: [EMAIL PROTECTED]
Subject: interfaces as service parameters?
Hi all,
Would the following work in Axis? And in JAX-RPC?
// the service to be exposed:
public interface MyServiceProvider extends java.rmi.Remote {
public MyData doSomething(MyData someData) throws
java.rmi.RemoteException;
}
// the interface that all data objects must implement:
public interface MyData extends java.io.Serializable {
}
// some specific data object:
public class SpecificData implements MyData {
public boolean flag;
}
???
Thx,
-- Oliver
*******************************************************************
DISCLAIMER: The information contained in this email
is confidential and is intended solely for the use of the
named addressee. Access, copying or re-use of the
information in it by any other person is not authorised.
********************************************************************