Web Services ASMX服务XML请求正在部分反序列化

9njqaruj  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(183)

我知道这个老技术,如果由我来决定的话,我的生活会有所不同。我对这个老技术相对比较陌生,我正在扩展一个现有的服务,我遇到了一个奇怪的问题。我有3个服务端点,其中2个按预期工作,但我对第三个的问题是,一些“框架”无法反序列化XML请求。

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <UpdateSale xmlns="http://tokenws.netgen.co.za/">
         <p_objrequest>
            <transactionTypeId>1</transactionTypeId>
            <tenderTypeId>1</tenderTypeId>
            <standardHeader>
               <requestId xmlns="">1_8</requestId>
               <localeId xmlns="" />
               <systemId xmlns="">asdf</systemId>
               <batchReference xmlns="">11</batchReference>
            </standardHeader>
            <account>
               <accountId xmlns="">123</accountId>
               <pin xmlns="" >123</pin>
            </account>
            <amount>
               <valueCode xmlns="">ZAR</valueCode>
               <enteredAmount xmlns="">30</enteredAmount>
               <nsfAllowed xmlns="">N</nsfAllowed>
            </amount>
            <lineItems>
               <LineItem>
                  <productCode>1</productCode>
                  <categoryCode>1</categoryCode>
                  <qty>1</qty>
                  <price>50</price>
                  <discountedPrice>0</discountedPrice>
                  <description>Buffet Breakfast</description>
               </LineItem>
            </lineItems>
         </p_objrequest>
         <netCredentials>
            <UserName xmlns="http://tempuri.org/">123</UserName>
            <Password xmlns="http://tempuri.org/">123</Password>
         </netCredentials>
      </UpdateSale>
   </soap:Body>
</soap:Envelope>

以上是xml,netCredentials已正确反序列化,但p_objrequest为空。
如何解决此问题?
下图为类:

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.6.1055.0")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://tokenws.netgen.co.za/")]
    public class Sale
    {

        private int transactionTypeIdField;

        private int tenderTypeIdField;

        private RequestStandardHeaderComponent standardHeaderField;

        private AccountComponent accountField;

        private string activatingField;

        private AmountComponent amountField;

        private CustomerInfoComponent customerInfoField;

        private PromotionCode[] promotionCodesField;

        private QuestionAndAnswer[] questionsAndAnswersField;

        private LineItem[] lineItemsField;

        private string includeTipField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
        public int transactionTypeId
        {
            get
            {
                return this.transactionTypeIdField;
            }
            set
            {
                this.transactionTypeIdField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
        public int tenderTypeId
        {
            get
            {
                return this.tenderTypeIdField;
            }
            set
            {
                this.tenderTypeIdField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 2)]
        public RequestStandardHeaderComponent standardHeader
        {
            get
            {
                return this.standardHeaderField;
            }
            set
            {
                this.standardHeaderField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 3)]
        public AccountComponent account
        {
            get
            {
                return this.accountField;
            }
            set
            {
                this.accountField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 4)]
        public string activating
        {
            get
            {
                return this.activatingField;
            }
            set
            {
                this.activatingField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 5)]
        public AmountComponent amount
        {
            get
            {
                return this.amountField;
            }
            set
            {
                this.amountField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 6)]
        public CustomerInfoComponent customerInfo
        {
            get
            {
                return this.customerInfoField;
            }
            set
            {
                this.customerInfoField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order = 7)]
        public PromotionCode[] promotionCodes
        {
            get
            {
                return this.promotionCodesField;
            }
            set
            {
                this.promotionCodesField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order = 8)]
        public QuestionAndAnswer[] questionsAndAnswers
        {
            get
            {
                return this.questionsAndAnswersField;
            }
            set
            {
                this.questionsAndAnswersField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order = 9)]
        public LineItem[] lineItems
        {
            get
            {
                return this.lineItemsField;
            }
            set
            {
                this.lineItemsField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 10)]
        public string includeTip
        {
            get
            {
                return this.includeTipField;
            }
            set
            {
                this.includeTipField = value;
            }
        }
    }
ars1skjm

ars1skjm1#

标记名和类/属性名必须匹配(包括大小写)。请参见以下内容:

[XmlRoot(ElementName= "UpdateSale", Namespace="http://tokenws.netgen.co.za/")]
    public class Sale
    {
    }
    [XmlRoot(ElementName= "netCredentials")]
    public class NetCredentials
    {
        [XmlElement(ElementName="UserName",Namespace="http://tempuri.org/")]
        public Name userName { get; set;} 
        [XmlElement(ElementName="Password",Namespace="http://tempuri.org/")]
        public Name password { get; set;} 
    }
    public class Name
    {
        [XmlText]
        public string name { get; set;}
    }

相关问题