将List <object>传递给WCF服务始终为null </object>

时间:2015-03-05 15:47:54

标签: c# web-services wcf soap

我有下面的对象:

[DataContract]
    public class MyListofProducts
    {
        [DataMember]
        public List<Product> Products { get; set; }

    }
[DataContract]
    public class Product
    {
        [DataMember]
        public string Alias { get; set; }
        [DataMember]
        public bool IsNew { get; set; }
        [DataMember]
        public bool IsVisible { get; set; }
        [DataMember]
        public int MinOrder { get; set; }
        [DataMember]
        public string OrderUnit { get; set; }
        [DataMember]
        public string TaxClass { get; set; }
        [DataMember]
        public float Weight { get; set; }
        [DataMember]
        public List<Item> AvailabilityComment { get; set; }
        [DataMember]
        public List<Item> Name { get; set; }
        [DataMember]
        public List<Item> Keywords { get; set; }
        [DataMember]
        public List<Item> Description { get; set; }
        [DataMember]
        public List<Item> LongDescription { get; set; }
        [DataMember]
        public List<ProductPrice> ProductPrices { get; set; }
        public List<Attribute> Attributes { get; set; }

    }

我的WCF运营合同如下:

public bool Create(MyListofProducts products)
            {
                var productConroller = new ProductController();
                return productConroller.Create(products);
            }

当我创建.net客户端时生成的肥皂请求如下(全部工作):

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
    <Create xmlns="http://BiggroupServices.IFSConnect/">
      <product xmlns:a="http://schemas.datacontract.org/2004/07/IFSConnect.Models" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Products>
          <a:Product>
            <a:Alias>ACA00</a:Alias>
            <a:AvailabilityComment>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value i:nil="true" />
              </a:Item>
            </a:AvailabilityComment>
            <a:Description>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value>Our Part Number: 00622415</a:Value>
              </a:Item>
            </a:Description>
            <a:IsNew>true</a:IsNew>
            <a:IsVisible>true</a:IsVisible>
            <a:Keywords>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value i:nil="true" />
              </a:Item>
            </a:Keywords>
            <a:LongDescription>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value i:nil="true" />
              </a:Item>
            </a:LongDescription>
            <a:MinOrder>1</a:MinOrder>
            <a:Name>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value>Screw In Plastic Thermostatic Cartridge ACA00</a:Value>
              </a:Item>
            </a:Name>
            <a:OrderUnit>each</a:OrderUnit>
            <a:ProductPrices>
              <a:ProductPrice>
                <a:CurrencyId>GBP</a:CurrencyId>
                <a:Price>25</a:Price>
                <a:TaxModel>dafsd</a:TaxModel>
              </a:ProductPrice>
            </a:ProductPrices>
            <a:TaxClass>UKSTD2</a:TaxClass>
            <a:Weight>0.1</a:Weight>
          </a:Product>
          <a:Product>
            <a:Alias>ACA01</a:Alias>
            <a:AvailabilityComment>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value i:nil="true" />
              </a:Item>
            </a:AvailabilityComment>
            <a:Description>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value>Our Part Number: 00622415 - Test update</a:Value>
              </a:Item>
            </a:Description>
            <a:IsNew>false</a:IsNew>
            <a:IsVisible>false</a:IsVisible>
            <a:Keywords>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value>Keywords</a:Value>
              </a:Item>
            </a:Keywords>
            <a:LongDescription>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value>Screw In Plastic Thermostatic Cartridge 2 - Long description</a:Value>
              </a:Item>
            </a:LongDescription>
            <a:MinOrder>10</a:MinOrder>
            <a:Name>
              <a:Item>
                <a:LanguageCode>en</a:LanguageCode>
                <a:Value>Screw In Plastic Thermostatic Cartridge ACA01</a:Value>
              </a:Item>
            </a:Name>
            <a:OrderUnit>akdfjgbvdajk</a:OrderUnit>
            <a:ProductPrices>
              <a:ProductPrice>
                <a:CurrencyId>GBP</a:CurrencyId>
                <a:Price>2500</a:Price>
                <a:TaxModel>dafsd</a:TaxModel>
              </a:ProductPrice>
            </a:ProductPrices>
            <a:TaxClass>UKSTD245</a:TaxClass>
            <a:Weight>100.1</a:Weight>
          </a:Product>
        </a:Products>
      </product>
    </Create>
  </s:Body>
</s:Envelope>

但是当传递下面的Soap请求时,它总是得到null:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <soap:Body>
        <Create xmlns="http://BiggroupServices.IFSConnect/">
            <Products>
                <Product>
                    <Alias xsi:type="xsd:string">AHA11</Alias>
                    <IsNew xsi:type="xsd:int">0</IsNew>
                    <IsVisible xsi:type="xsd:int">1</IsVisible>
                    <MinOrder xsi:type="xsd:float">1.0</MinOrder>
                    <OrderUnit xsi:type="xsd:string">each</OrderUnit>
                    <TaxClass xsi:type="xsd:string">UKSTD2</TaxClass>
                    <Weight xsi:type="xsd:float">1.000</Weight>
                    <AvailabilityComment>
                        <Item>
                            <LanguageCode>en</LanguageCode>
                            <Value xsi:nil="true" />
                        </Item>
                    </AvailabilityComment>
                    <Name>
                        <Item>
                            <LanguageCode>en</LanguageCode>
                            <Value>Heritage Bath Rack Vintage Gold</Value>
                        </Item>
                    </Name>
                    <Keywords>
                        <Item>
                            <LanguageCode>en</LanguageCode>
                            <Value xsi:nil="true" />
                        </Item>
                    </Keywords>
                    <Description>
                        <Item>
                            <LanguageCode>en</LanguageCode>
                            <Value>Our Part Number: AHA11</br></br></Value>
                        </Item>
                    </Description>
                    <LongDescription>
                        <Item>
                            <LanguageCode>en</LanguageCode>
                            <Value xsi:nil="true" />
                        </Item>
                    </LongDescription>
                    <Text>
                        <Item>
                            <LanguageCode>en</LanguageCode>
                            <Value xsi:nil="true" />
                        </Item>
                    </Text>
                    <ProductPrices>
                        <ProductPrice>
                            <CurrencyID>GBP</CurrencyID>
                            <Price>100.000</Price>
                            <TaxModel>net</TaxModel>
                        </ProductPrice>
                    </ProductPrices>

                </Product>
            </Products>
        </Create>
    </soap:Body>
</soap:Envelope>

我不明白为什么WCF在第二种情况下无法序列化对象列表?

所有我发现差异低于位。

<product xmlns:a="http://schemas.datacontract.org/2004/07/IFSConnect.Models" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

任何建议都将受到赞赏。

编辑1:

[ServiceContract(Namespace = "http://BiggroupServices.IFSConnect/")]
public interface IProductService
    {
        [OperationContract]
        bool Create(MyListofProducts product);
    }

0 个答案:

没有答案