I'm consuming a SOAP web service in a C# application (.NET Framework 4.8) that uses a proxy generated via xsd.exe from the service's XSD.
In the XSD there is a field that expects a monetary amount, that is defined as follows:
<xs:simpleType name="HHAmountType">
<xs:restriction base="xs:decimal">
<xs:pattern value="(\+|\-)?\d{1,7}\.\d\d"/>
</xs:restriction>
</xs:simpleType>
And the service throws an exception back if I provide a value such as "0". From looking at that XML Schema, it looks like it would expect that to be "0.00", and that matches some other documentation that describes the field. What I can't work out is what to do to the generated class to allow me to output that number with 2 decimal places consistently. The class has provided a property that is a decimal, that I'm setting to a value (in this case it's 0), and at the moment there are no additional attributes added to it.
/// <remarks/>
public decimal Amount {
get {
return this.amountField;
}
set {
this.amountField = value;
}
}
Can anyone steer me in the direction of any attributes etc. that would allow me to do this, or will I need to change this to a string property and handle that formatting myself or something?
Try following :
private decimal _amountField { get; set; }
public string Amount
{
get
{
return this._amountField.ToString("D2");
}
set
{
this._amountField = decimal.Parse(value);
}
}