Development

From Agility
Revision as of 07:51, 28 April 2016 by Artur (Talk | contribs) (Tips & Tricks)

Jump to: navigation, search

Tips & Tricks

Specifying minOccurs=0 for non-string fields in WSDL generated from C# Web service method

If tthere is a need for Xml element to be optional for non-string field in generated WSDL, the field definition needs to be coupled with the XXXSpecified boolean field definition within the same class. To stop the logical field from being included in the WSDL, [XmlIgnore] attribute can be used. Example below:

            /// <remarks/>
            public Decimal? PurchaseCost
            {
                get
                {
                    return this.purchaseCostField;
                }
                set
                {
                    this.purchaseCostField = value; 
                }
            }

            // this has been provided to force WSDL generator to put minoccurs=0 into PurchaseCost element definition
            [System.Xml.Serialization.XmlIgnore]
            public bool PurchaseCostSpecified
            {
                get
                {
                    return true;
                }
            }