A better solution might be to serialize this float as a string and do your
own mapping for null values internally as follows:
private float price;
private bool hasPrice;
[XmlElement("Pri ce")] // this is the serializable property
public string PriceString {
get {
if (!hasPrice) return null;
return price.ToString( );
}
set {
this.Price = float.Parse(val ue);
}
}
[XmlIgnore] // this is not serialized, but it is what you use
in your program.
public float Price {
get { return this.price; }
set { this.price = value; hasPrice = true; }
}
If you are using .NET 2.0 then you can simplify this further using the new
nullable type operator "?" as follows:
private float? price;
[XmlElement("Pri ce")] // this is the serializable property
public string PriceString {
get {
if (!price.HasValu e) return null;
return price.Value.ToS tring();
}
set {
this.Price = float.Parse(val ue);
}
}
[XmlIgnore] // this is not serialized, but it is what you use
in your program.
public float Price {
get { return this.price.HasV alue ? this.price.Valu e : 0; }
set { this.price = value; }
}
The XmlSerializer in .NET 2.0 also handles the nullable type, but it writes
out <Price xsi:nil="true" />. If this is ok then you can simplify it even
further and write:
public float? Price;
and be done!
"Robb Gilmore" <rg******@newsg roup.nospam> wrote in message
news:F8******** *************** ***********@mic rosoft.com...
Hello,
We have a C#.NET app which is calling a Java webservice. We use the wsdl
file exportted from the java webservice to create our web-reference in
Visual
Studio. We are able to create the parameter classes and call the
webservice
just fine.
Our problem is, within our .Net app, we have some value objects ( like
floats, for instance ) which are meant to be null. Since there is no null
float, we use float.minvalue to indicate a null in this field. When we
call
the webservice, we don't want to pass float.minvalue for those fields, we
would like to translate it back into a true null and pass that.
Our first attempt was to edit our .wsdl file and replace nillable="true"
with minOccurs="0". Then, within our .Net code, we do not set the float
value at all when we intend for it to null. However this had the effect
of
sending nulls for all of our float values.
Can you tell me the recommended way to send a null value in a float field,
if there is a recommended way?
thanks
Robb