You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Muhammad Alsebaeyie <mu...@pharmaoverseas.com> on 2005/03/01 14:46:32 UTC

Weak-Typed Collections and .Net, got it!

Hi,
I had a specific problem that I wanted to make an axis service that 
sends a complex object containing weak-typed collections, specifically 
java.util.Set and java.util.List... I needed the service to interoperate 
with .Net and I had no control over the class structure.
Everything I read said this was a bad Idea, but I finally got it to 
work,so I  thought I'd share...
First, I used Axis 1.2RC2, Axis 1.1 doesn't work.
I used the java2wsdl->wsdl2java method, I didn't build everything by hand.

Now, Axis 1.2RC2 generates a wrapper for all collections which it 
encounters mapping it into an array of xsd:anyType, the name of the 
wrapper complex type is (Array of XSD anytype).

There are two problems with that wrapper:
1-there is bug in Axis that makes the bean serializer stop at 
java.util.* (I think), so the resulting wsdl has a namespace (tnX) where 
x is an arbitrary number depending on your class structure that doesn't 
exist...
2-Even if you fix the above, the problem is that .Net doesn't like array 
warppers, so it doesn't work correctly

so what I did is comment the complex type wrapper, and in every element 
that was an array, I added maxOccurs="unbounded' and minOccurs="0" and 
made it of type wsdl:type="xsd:anyType"

The only problem left is that we must also include in the WSDL the 
classes that we will cast the resulting Object[] to, which may not be 
included by default because the types are weak, so I added these to the 
extraclasses parameter in java2wsdl.

Now the wsdl is ok, but if we generate the service from it, it will make 
all the class structure again and convert all collections into arrays of 
Object[], which was not desirable in my case, so I used helpergen="true" 
in wsdl2java to separate the axis metadata from the actual classes, and 
I only used those helper classes coupled with the original class 
structure in the service.

And it works! tested on both a java and a .Net client and the client 
recieves an array of Object[] that it understands it can cast into the 
desired object...

take care though that the wsdl generated from using <serviceurl>?wsdl 
will be the original not-working one, so the only shortcoming here is 
that I have to move the wsdl manually.

Hope this helps people and the Axis team...

-- 
Best Regards,
Muhammad Alsebaeyie


---
[This E-mail scanned for viruses by F-Prot]