views:

462

answers:

2

Hi *

I have a web service in java that implemented on jax-ws. This web service return an generic list of User. It's working very good :).

@Stateless(name = "AdminToolSessionEJB")
@RemoteBinding(jndiBinding = "AdminToolSessionRemote")
@Remote(AdminToolSessionRemote.class)
@WebService
public class AdminToolSessionBean implements AdminToolSessionRemote {
...
@WebMethod(operationName = "GetAllUsers")
@WebResult(name = "AllUsers")
public List<User> getAllUsers() {
    return userSessionRemote.getAllUsers();
}
...
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "User")
public class User extends BasicDataTransferObject {
...
@XmlElement(name = "Groups")
private List<Group> groups;
...
}

But I will use this web service in .Net Applications. When I add this web service as a wcf service or web service in VS2005 or VS2008 or VS2010, VS generate array instead od generic list 'Group[] Groups'. I change 'Collection Type' in 'Configuration Service Reference ...' dialog to 'System.Collections.Generic.List' but VS generate array :(.

I need to VS generate generic list or ArrayList, what I should to do?

+1  A: 

I would recommend not using language specific constructs in a webservice, since a webservice is meant to be language agnostic.

If you really want to, but you shouldn't you will have to write a specific serializer/deserialiser of which you can not be sure that it will work in all language.

I would just stick to an array and then write a wrapper in yo language of choice.

chrissie1
+1  A: 

I'm not sure how to define this in java. However, in my C# service, my main transaction parameter (a purchase order) contains a list of line items defined like this:

private LineItems LineItemsField;
[DataMember(Order=13, EmitDefaultValue=false)]
public LineItems LineItems {
    get { return this.LineItemsField; }
    set { this.LineItemsField = value; }
}

LineItems is another C# class, defined like this:

[CollectionDataContract(Namespace="")]
public class LineItems : List<LineItem>
{
}

LineItem is the actual class that contains the line item fields.

The LineItems appears in WSDL as:

<s:element minOccurs="0" maxOccurs="1" name="LineItems" type="tns:ArrayOfLineItem" />

ArrayOfLineItem is defined as:

<s:complexType name="ArrayOfLineItem">
    <s:sequence>
        <s:element minOccurs="0" maxOccurs="unbounded" name="LineItem" nillable="true" type="tns:LineItem" />
    </s:sequence>
</s:complexType>

And of course, the LineItem class itself is defined elsewhere. Hopefully that helps.

Mike Hanson
Thanks for your help, yes in .Net, web service generate WSDL like your sample for List and Collection. But I couldn't make this WSDL by jaxb, for test I write a XSD file and make a structure like that your says unfortunately this handy WSDL doesn't generate List too. No problem my colleague write a mapper to map our DTO to our wanted Model. This is a good workaround but every time I have free time again test your idea.
Amir Borzoei