c#中生成的代理类中的列表与数组

时间:2011-12-09 12:31:03

标签: c# wcf

我有一个WCF服务,当我用svcutil生成客户端代理类时,它将我的列表属性更改为数组。是否有一个选项可以确保我在不修改C#生成的类的情况下维护列表?

//The object in the service…

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://brax.com/data/Query")]
public partial class PayloadType
{
    private List<PersonType> personBasedQueryField;
    private List<LocationType> locationBasedQueryField;


//Generated class...

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://brax.com/data/Query")]
public partial class PayloadType
{
    private PersonType[] personBasedQueryField;
    private LocationType[] locationBasedQueryField;

3 个答案:

答案 0 :(得分:3)

是的,Visual Studio中的服务参考中有选项。您可以选择将集合生成为List。

更新:如果您使用的是svcutil.exe,则可以使用此选项:

/collectionType:<type>

答案 1 :(得分:2)

通过在Visual Studio中添加服务引用来创建客户端代理时,您可以稍后编辑该配置。在该编辑对话框中,您可以指定是否要包含数组,列表,ObservableCollections(我认为还有更多选项)。

enter image description here

使用svcutil我不知道是否可以更改该选项。

答案 2 :(得分:0)

右键单击ServiceReference,选择“配置服务引用”。并将Collection类型更改为System.Collections.Generic.List。

相关问题