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
"Jeffrey Tan[MSFT]" - 12 Oct 2005 09:10 GMT
Hi Robb,
Currently we are looking for someone to help you on this issue, we will
reply to you ASAP. Thanks for your understanding.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Kevin Yu [MSFT] - 13 Oct 2005 07:27 GMT
Hi Robb,
As far as I know, there is no way to send a null for value types in .NET
1.1, because the value types cannot be null. In .NET 2.0 there will be
nullable types available. But I don't think java will support this. So,
currently, your resolution seems to be fine, and I don't have better ones
than yours.
Kevin Yu

Signature
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
Chris Lovett - 14 Oct 2005 18:34 GMT
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("Price")] // this is the serializable property
public string PriceString {
get {
if (!hasPrice) return null;
return price.ToString();
}
set {
this.Price = float.Parse(value);
}
}
[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("Price")] // this is the serializable property
public string PriceString {
get {
if (!price.HasValue) return null;
return price.Value.ToString();
}
set {
this.Price = float.Parse(value);
}
}
[XmlIgnore] // this is not serialized, but it is what you use
in your program.
public float Price {
get { return this.price.HasValue ? this.price.Value : 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!
> Hello,
>
[quoted text clipped - 23 lines]
> thanks
> Robb