0

我正在使用 svcutil 从 XSD 生成数据合同类。这是 XSD 的一个片段:

<xs:element name="Fulfilment">

....
....
    <xs:element name="Products" minOccurs="0" maxOccurs="1">
      <xs:complexType>
         <xs:sequence>
             <xs:element minOccurs="0" maxOccurs="unbounded" 
                     type="Product" name="Product" />
         </xs:sequence>
      </xs:complexType>
    </xs:element>

不是将<Products>元素生成为Fulfilment对象的列表属性,而是生成的代码是这样的:

 public ProductsType Products
        {
            get
            {
                return this.ProductsField;
            }
            set
            {
                this.ProductsField = value;
            }
        }

     public class ProductsType : System.Collections.Generic.List<Product>
     {
     }

有没有办法让 svcutilProducts直接将属性生成为产品的通用列表,而不是创建从列表继承的“ProductsType”类并使用它?

4

3 回答 3

3

你去 svcutil.exe http://localhost/Services/Sample.svc?wsdl /ct:System.Collections.Generic.List`1 如果这是你想要的答案,请打勾

于 2011-01-14T20:19:56.827 回答
0

是的,当您在 VS 上添加服务引用时,您可以决定如何从 WCF 转换集合。

于 2011-01-14T02:55:30.603 回答
0

有关集合序列化的详细讨论,请参见http://msdn.microsoft.com/en-us/library/aa347850.aspx

我问了一个类似的问题(Is there a reason for the nested generic collection classes in svcutil generated code?),那个 MSDN 文档为我回答了这个问题。只要您想使用 svcutil,您似乎就被多余的内部类所困扰。我的结论是,由于它生成的代码和消费者的接口在两种情况下都是相同的,我只是不关心那个额外的类。

于 2012-06-08T15:42:56.047 回答