on 10-04-2005 8:53 PM
Hello All,
I am publishing a method from a stateless session bean as a webservice. The interface of this method passes to custom Data Objects. One of the Data Objects has an ArrayList of another custom Data Object as a variable. In the WSDL after publishing i see this statement:
- <xs:complexType name="ArrayList">
- <xs:sequence>
<xs:element name="ArrayList" minOccurs="0" maxOccurs="unbounded" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
Why is this "anyType" not being shown as of type XYZ data object which I may have?
Is there any way i can change the WSDL during generation to show the actual data type of the elements of the Arraylist?
All help is greatly appreciated.
Thanks,
Murtaza.
Hi Murtaza,
instead of passing Java collections, you should convert into and wrap them by arrays. For details see http://www-128.ibm.com/developerworks/xml/library/ws-tip-coding.html
Hope it helps
Detlev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Detlev,
Converting to arrays is always an option. Its just not the best one especially if you have several data objects each with a large number of variables. I agree there is no way of resolving at the time the service is published the exact contents of each element of the Array list, which could be any number of different items (custom Data objects, followed by Strings, followed by Integer objects, etc). However, in the event that all the elements of the ArrayList are of one homogenous type (Say Data Object abc, or String) should'nt there be some way to specify this so that the WSDL is published with the element type correctly?
Let me know what you think.
Thanks,
Murtaza.
Hi, I have been watching this thread and wanted to make a suggestion. You can create public attributes in you DTO object that have no accessors. Now run the Web Service Wizard or the Virtual Interface Wizard and then check the VI under the types tab (of course expose the object by adding it to an ejb method). You will see the MyCustomObject and Integer in the list so this will be generated on the consumer side via wsdl later. Here is an example of what I am talking about:
DTOClass used to transport object,Lists etc...
import java.io.Serializable;
import java.util.ArrayList;
public class MyDataObjectDTO implements Serializable{
private ArrayList myList;
/* using as a placeholder so VirtualInterface (later WSDL)
generator knows of this object.
This object will be used in the
setMyList but WS needs to expose
this to my consumers.
The following are used by WS wsdl generator only.
*/
public MyCustomObject myCustomObject;
public Integer myInteger;
//now MyCustomObject and Integer can be used in the ArrayList
public void setMyList(ArrayList myList){
this.myList = myList;
}
}
//End DTO CLASS
Now the Custom object MyCustomObject:
import java.io.Serializable;
public class MyCustomObject implements Serializable {
private String name;
private Integer age;
public Integer getAge() {return age;}
public String getName() {return name;}
public void setAge(Integer integer) {age = integer;}
public void setName(String string) {name = string;}
}
//Notice that the stubbed object in the DTO is public, NULL and without accessors. I would love to make it private but the VI knows then it does not have to map it....
This is not as elegant but it does give us an option instead of creating a new data structure of classes that look remarkably similar to our current structure but with arrays for collections. Or even worse, make us change our current structure just to squeeze it through a WS whose implementation is dated (image a structure with 50 custom objects and they are all passed in Lists). So in conclusion, create a wrapper DTO and add ALL objects that are expected in any serializable collection. Now you have one object being used as the vehicle and you preserve your object structure!
Hope this helps,
Brian
Thanks Brian,
That is how we are currently declaring the Arraylist variable. However, when the WSDL is published we get the "anyType" which is what we want to replace, with the type of the elements of the ArrayList. I wanted to know if there is any way we can do this. If not then is it a limitation of the SAP implementation or is that how the Web Service standard is defined?
Thanks,
Murtaza.
Hi Murtaza,
You can place any type of objects in Arraylist. So, when your get WSDL for this, it always gives type as "anytype". But, at runtime you can check the instanceof that object is of type XYZ.
but, as you are passing variable of type Arraylist, design time container doesd't know the type of the contents inside this Arraylist.
Regards,
Bhavik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.