如何配置WebService返回ArrayList而不是Array? [英] How to config WebService to return ArrayList instead of Array?
问题描述
我有一个用jax-ws实现的Java Web服务.该Web服务返回用户的通用列表.它的工作非常好:).
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;
...
}
但是我将在.Net应用程序中使用此Web服务.当我在VS2005或VS2008或VS2010中将此Web服务添加为wcf服务或Web服务时,VS会生成数组,而不是泛型列表'Group [] Groups'.我将配置服务参考..."对话框中的集合类型"更改为"System.Collections.Generic.List",但VS生成了数组:(.
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 :(.
我需要VS生成通用列表或ArrayList,我该怎么办?
I need to VS generate generic list or ArrayList, what I should to do?
推荐答案
我不确定如何在Java中定义它.但是,在我的C#服务中,我的主要交易参数(采购订单)包含如下定义的订单项列表:
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
是另一个C#类,定义如下:
LineItems
is another C# class, defined like this:
[CollectionDataContract(Namespace="")]
public class LineItems : List<LineItem>
{
}
LineItem
是包含订单项字段的实际类.
LineItem
is the actual class that contains the line item fields.
LineItems
在WSDL中显示为:
The LineItems
appears in WSDL as:
<s:element minOccurs="0" maxOccurs="1" name="LineItems" type="tns:ArrayOfLineItem" />
ArrayOfLineItem
定义为:
<s:complexType name="ArrayOfLineItem">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="LineItem" nillable="true" type="tns:LineItem" />
</s:sequence>
</s:complexType>
当然,LineItem
类本身是在其他地方定义的.希望有帮助.
And of course, the LineItem
class itself is defined elsewhere. Hopefully that helps.
这篇关于如何配置WebService返回ArrayList而不是Array?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!