Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使XML有数据,C#中的XML反序列化也会返回空数组_C#_Asp.net_Xml_Soap - Fatal编程技术网

即使XML有数据,C#中的XML反序列化也会返回空数组

即使XML有数据,C#中的XML反序列化也会返回空数组,c#,asp.net,xml,soap,C#,Asp.net,Xml,Soap,我正在尝试反序列化XML <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org

我正在尝试反序列化XML

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body>
      <ns1:catalogProductListResponse>
         <storeView SOAP-ENC:arrayType="ns1:catalogProductEntity[609]" xsi:type="ns1:catalogProductEntityArray">
            <item xsi:type="ns1:catalogProductEntity">
               <product_id xsi:type="xsd:string">36</product_id>
               <sku xsi:type="xsd:string">000975</sku>
               <name xsi:type="xsd:string">Beauty Dermo HTM - Vacuoterapia</name>
               <set xsi:type="xsd:string">4</set>
               <type xsi:type="xsd:string">simple</type>
               <category_ids SOAP-ENC:arrayType="xsd:string[9]" xsi:type="ns1:ArrayOfString">
                  <item xsi:type="xsd:string">4</item>
               </category_ids>
               <website_ids SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:ArrayOfString">
                  <item xsi:type="xsd:string">1</item>
               </website_ids>
            </item>
            <item xsi:type="ns1:catalogProductEntity">
               <product_id xsi:type="xsd:string">37</product_id>
               <sku xsi:type="xsd:string">004279</sku>
               <name xsi:type="xsd:string">Effect HTM - Radiofrequência</name>
               <set xsi:type="xsd:string">4</set>
               <type xsi:type="xsd:string">simple</type>
               <category_ids SOAP-ENC:arrayType="xsd:string[8]" xsi:type="ns1:ArrayOfString">
                  <item xsi:type="xsd:string">4</item>
               </category_ids>
               <website_ids SOAP-ENC:arrayType="xsd:string[1]" xsi:type="ns1:ArrayOfString">
                  <item xsi:type="xsd:string">1</item>
               </website_ids>
            </item>
            ...[OTHER MANY ITENS]
         </storeView>
      </ns1:catalogProductListResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

36
000975
美容真皮HTM-真空特拉皮亚
4.
简单的
4.
1.
37
004279
效果HTM-射频
4.
简单的
4.
1.
…[其他许多ITEN]
在这个班

public class ProductListResponse
{
    // NOTE: Generated code may require at least .NET Framework 4.5 or .NET Core/Standard 2.0.
    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.xmlsoap.org/soap/envelope/", IsNullable = false)]
    public partial class Envelope
    {
        private EnvelopeBody bodyField;

        private string encodingStyleField;

        /// <remarks/>
        public EnvelopeBody Body
        {
            get
            {
                return this.bodyField;
            }
            set
            {
                this.bodyField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
        public string encodingStyle
        {
            get
            {
                return this.encodingStyleField;
            }
            set
            {
                this.encodingStyleField = value;
            }
        }
    }

    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    public partial class EnvelopeBody
    {
        private catalogProductListResponse catalogProductListResponseField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Namespace = "urn:Magento")]
        public catalogProductListResponse catalogProductListResponse
        {
            get
            {
                return this.catalogProductListResponseField;
            }
            set
            {
                this.catalogProductListResponseField = value;
            }
        }
    }

    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "urn:Magento")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "urn:Magento", IsNullable = false)]
    public partial class catalogProductListResponse
    {
        private storeView storeViewField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("storeView")]
        public storeView storeView
        {
            get
            {
                return this.storeViewField;
            }
            set
            {
                this.storeViewField = value;
            }
        }
    }

    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(TypeName = "catalogProductEntityArray")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class storeView
    {
        private storeViewItem[] itemField;

        private string arrayTypeField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("item")]
        public storeViewItem[] item
        {
            get
            {
                return this.itemField;
            }
            set
            {
                this.itemField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://schemas.xmlsoap.org/soap/encoding/")]
        public string arrayType
        {
            get
            {
                return this.arrayTypeField;
            }
            set
            {
                this.arrayTypeField = value;
            }
        }
    }

    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(TypeName = "catalogProductEntity")]
    public partial class storeViewItem
    {

        private ushort product_idField;

        private string skuField;

        private string nameField;

        private byte setField;

        private string typeField;

        private storeViewItemCategory_ids category_idsField;

        private storeViewItemWebsite_ids website_idsField;

        /// <remarks/>
        public ushort product_id
        {
            get
            {
                return this.product_idField;
            }
            set
            {
                this.product_idField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public string sku
        {
            get
            {
                return this.skuField;
            }
            set
            {
                this.skuField = value;
            }
        }

        /// <remarks/>
        public string name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
            }
        }

        /// <remarks/>
        public byte set
        {
            get
            {
                return this.setField;
            }
            set
            {
                this.setField = value;
            }
        }

        /// <remarks/>
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        public storeViewItemCategory_ids category_ids
        {
            get
            {
                return this.category_idsField;
            }
            set
            {
                this.category_idsField = value;
            }
        }

        /// <remarks/>
        public storeViewItemWebsite_ids website_ids
        {
            get
            {
                return this.website_idsField;
            }
            set
            {
                this.website_idsField = value;
            }
        }
    }

    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    public partial class storeViewItemCategory_ids
    {

        private byte[] itemField;

        private string arrayTypeField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("item")]
        public byte[] item
        {
            get
            {
                return this.itemField;
            }
            set
            {
                this.itemField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://schemas.xmlsoap.org/soap/encoding/")]
        public string arrayType
        {
            get
            {
                return this.arrayTypeField;
            }
            set
            {
                this.arrayTypeField = value;
            }
        }
    }

    /// <remarks/>
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    public partial class storeViewItemWebsite_ids
    {

        private byte itemField;

        private string arrayTypeField;

        /// <remarks/>
        public byte item
        {
            get
            {
                return this.itemField;
            }
            set
            {
                this.itemField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified, Namespace = "http://schemas.xmlsoap.org/soap/encoding/")]
        public string arrayType
        {
            get
            {
                return this.arrayTypeField;
            }
            set
            {
                this.arrayTypeField = value;
            }
        }
    }
}
公共类ProductListResponse
{
//注意:生成的代码可能至少需要.NET Framework 4.5或.NET Core/Standard 2.0。
/// 
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
[System.Xml.Serialization.XmlRootAttribute(命名空间=”http://schemas.xmlsoap.org/soap/envelope/“,IsNullable=false)]
公共部分类信封
{
私人信封盒体字段;
私有字符串编码样式字段;
/// 
公共信封主体
{
得到
{
返回此.bodyField;
}
设置
{
this.bodyField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified)]
公共字符串编码样式
{
得到
{
返回此.encodingStyleField;
}
设置
{
this.encodingStyleField=值;
}
}
}
/// 
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,命名空间=”http://schemas.xmlsoap.org/soap/envelope/")]
公共部分类信封体
{
私有目录ProductListResponse目录ProductListResponseField;
/// 
[System.Xml.Serialization.xmlementAttribute(Namespace=“urn:Magento”)]
公共目录ProductListResponse目录ProductListResponse
{
得到
{
返回此.catalogProductListResponseField;
}
设置
{
this.catalogProductListResponseField=值;
}
}
}
/// 
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true,Namespace=“urn:Magento”)]
[System.Xml.Serialization.XmlRootAttribute(Namespace=“urn:Magento”,IsNullable=false)]
公共部分类catalogProductListResponse
{
私有storeView storeViewField;
/// 
[System.Xml.Serialization.XmlElementAttribute(“storeView”)]
公共存储视图存储视图
{
得到
{
返回此.storeViewField;
}
设置
{
this.storeViewField=值;
}
}
}
/// 
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(TypeName=“catalogProductEntityArray”)]
[System.Xml.Serialization.XmlRootAttribute(Namespace=”“,IsNullable=false)]
公共部分类storeView
{
private storeViewItem[]项目字段;
私有字符串arrayTypeField;
/// 
[System.Xml.Serialization.xmlementAttribute(“项”)]
公共存储视图项[]项
{
得到
{
返回此.itemField;
}
设置
{
this.itemField=值;
}
}
/// 
[System.Xml.Serialization.XmlAttributeAttribute(Form=System.Xml.Schema.XmlSchemaForm.Qualified,命名空间=”http://schemas.xmlsoap.org/soap/encoding/")]
公共字符串数组类型
{
得到
{
返回此.arrayTypeField;
}
设置
{
this.arrayTypeField=值;
}
}
}
/// 
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(TypeName=“catalogProductEntity”)]
公共部分类storeViewItem
{
私人ushort product_idField;
私有字符串字段;
私有字符串名称字段;
专用字节设置字段;
私有字符串类型字段;
private storeViewItemCategory\u ID category\u ID字段;
private StoreViewItem网站\u ID网站\u ID字段;
/// 
公共ushort产品标识
{
得到
{
将此产品返回到\u i字段;
}
设置
{
this.product_idField=值;
}
}
/// 
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
公共字符串sku
{
得到
{
返回此.sku字段;
}
设置
{
this.sku字段=值;
}
}
/// 
公共字符串名
{
得到
{
返回此.nameField;
}
设置
{
this.nameField=值;
}
}
/// 
公共字节集
{
得到
{
返回此.setField;
}
设置
{
var deserializedDocument = SerializacaoHelper.Deserialize<ProductListResponse.Envelope>(xmlDocument);

public static T Deserialize<T>(XmlDocument xmlDoc)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(T));

        MemoryStream xmlStream = new MemoryStream();
        xmlDoc.Save(xmlStream);
        xmlStream.Position = 0;
        T obj = (T)serializer.Deserialize(xmlStream);

        xmlStream.Flush();

        return obj;
    }