Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web service Inheritance

Status
Not open for further replies.

DevinWhalen

Programmer
Jan 22, 2008
4
CA
Hi,

I am having a problem with inheritance in my webservice. I have a webservice that is working fine, but now I want to modify it to be more generic. I want the parameter to the operation to be an abstract type that I can have other objects inherit from and be sent to the same webservice end point. Then in the endpoint I can cast them into the appropriate type.

I have modified my WSDL so that the operation accepts an abstract type as a parameter and I have set up my two objects to inherit from this one abstract type. When I build my webservice off the wsdl the jax-ws generated sources are generated fine. My abstract object is built and the two objects that inherit from it are built. The java code for my operation is fine too, it lets me cast from the abstract type into the other two types.

The issues comes when I send my requests into the operation, when the soap request comes in, the abstract object is always null. Is what I am trying not possible?

Here is how I did it (this is just the pertinent stuff)

WSDL:

Schema definitions
Code:
<!-- abstract type -->
 <xsd:element name="AbstractType" abstract="true" type="ns:AbstractType" />
            <xsd:complexType name="AbstractType" />
            
<!-- first type to inherit -->
             <xsd:complexType name="Type1">
                <xsd:complexContent>
                    <xsd:extension base="ns:AbstractType">
                        <xsd:sequence>
                            <xsd:element name="EmployeeName" type="xsd:string"/>
                            <xsd:element name="Password" type="xsd:string"/>
                            <xsd:element name="EmployeeID" type="xsd:string"/>
                            <xsd:element name="OfficeId" type="xsd:string"/>
                        </xsd:sequence>
                    </xsd:extension>
                </xsd:complexContent>
            </xsd:complexType>
            <xsd:element xmlns:otns="[URL unfurl="true"]http://www.otherexample.com"[/URL] name="Type1" type="otns:Type1"/>
            
<!-- second type -->
            <xsd:complexType name="Type2">
                <xsd:complexContent>
                    <xsd:extension base="ns:AbstractType">
                        <xsd:sequence>
                            <xsd:element name="Username" type="xsd:string"/>
                            <xsd:element name="SecurityString" type="xsd:string"/>
                            <xsd:element name="IPAddress" type="xsd:string"/>
                            <xsd:element name="LoginUrl" type="xsd:string"/>
                        </xsd:sequence>
                    </xsd:extension>
                </xsd:complexContent>
            </xsd:complexType>
            <xsd:element xmlns:tns="[URL unfurl="true"]http://www.example.com"[/URL] name="Type2" type="tns:Type2"/>


Operation Definition:
Code:
<!-- operation accepts the Abstract type so I should be able to 
send in either Type1 or Type2 -->
 <message name="logMeIn">
        <part name="mydata" element="vc:RequestData"/>
        <part name="headerStuff" element="ns:AbstractType" />
    </message>



Then in my java code for the operation the headerStuff object comes in as null. However, when I change the WSDL to accept either Type1 or Type2 and send the corresponding requests, the headerStuff comes in fine.

Any advice? Is this even possible?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top