Home > Net >  C# issue with WDSL XML serialization and matching assignment
C# issue with WDSL XML serialization and matching assignment

Time:12-31

It seems that the docs, WDSL and C# code are not in sync....

I'm trying to place a bunch of addon elements that are a complex type.

Here is the XML

        <ns1:AddOns>
          <ns1:AddOnV17>
            <ns1:Amount>0.00</ns1:Amount>
            <ns1:AddOnType>SC-A-HP</ns1:AddOnType>
          </ns1:AddOnV17>
        </ns1:AddOns>

Further digging finds that I can access this AddOns through C# under a rate object.

the Reference code for the element is as follows:

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Order=30)]
        public AddOnV17[] AddOns {
            get {
                return this.addOnsField;
            }
            set {
                this.addOnsField = value;
                this.RaisePropertyChanged("AddOns");
            }
        }

and the AddOnV17 defined as:

    public partial class AddOnV17 : object, System.ComponentModel.INotifyPropertyChanged {
        
        private decimal amountField;
        
        private AddOnTypeV17 addOnTypeField;
        
        private string addOnDescriptionField;
        
        private AddOnTypeV17[][] requiresAllOfField;
        
        private AddOnTypeV17[] prohibitedWithAnyOfField;
        
        private string missingDataField;
        
        public AddOnV17() {
            this.amountField = ((decimal)(0.0m));
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=0)]
        [System.ComponentModel.DefaultValueAttribute(typeof(decimal), "0.0")]
        public decimal Amount {
            get {
                return this.amountField;
            }
            set {
                this.amountField = value;
                this.RaisePropertyChanged("Amount");
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public AddOnTypeV17 AddOnType {
            get {
                return this.addOnTypeField;
            }
            set {
                this.addOnTypeField = value;
                this.RaisePropertyChanged("AddOnType");
            }
        }
     }

This line gets an error

AddOns = new AddOnV17[] { Amount = (decimal)0.00, },

Error CS0103 The name 'Amount' does not exist in the current context

This is not clear as to why since the Def for the AddOnV17 type does include the Amount property.

What did I miss-understand? I'm in the correct Rate Object.

CodePudding user response:

The Amount field is defined in AddOnV17, so the AddOns should be defined like this:

AddOns = new AddOnV17[] {
    new AddOnV17 { Amount = (decimal)0.00 }
}
  • Related