473,549 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send a null value for a float variable?

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
Nov 12 '05 #1
3 7057
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
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 12 '05 #2
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
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #3
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

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2085
by: Kenny Mullican | last post by:
I am using complex types in order to support serialization/deserialization of floating point numbers, since floating points can't be null. I've seen how to suppress attributes that are "not specified", such as having a float member called Value, and a bool member called ValueSpecified. This instructs the XML Serializer to omit that...
102
5936
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV" ( i am talking of unix machine ) while trying to read that location. Then how can i distinguish between a NULL pointer and an invalid location ?...
29
3719
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's compiler dependent (and that NULL might be anything, but it is always NULL). The source snippet is below. The question is: - When I use calloc to...
4
2619
by: Learner | last post by:
Hello, I have database field called 'PullAHead' defined as a bit field. Now if user doesn't pick a 'Yes' or 'No' in the front I need to be able to send a null value into the 'PullAHead' field in the database. This is how I am trying to do it.... Dim PullAhead As Integer PullAhead = Nothing If _lblpullahead.Visible = True Then
7
2132
by: dotnetnoob | last post by:
i keep getting Object references not set to an instance of an object from this code: Private Sub EqBinding() Dim x As Integer x = 0 Do If CStr(arlsType.Item(x)) = "Bacnet Point" Then Dim str1, str2 As String str1 = CStr(arlsFilePath.Item(x))
14
3005
by: mast2as | last post by:
Hi everyone, I am trying to implement some specs which specify that an array of parameter is passed to a function as a pointer to an array terminated by a NULL chatacter. That seemed fairly easy to implement. I had a special Malloc function that would allocated the number of needed bytes for the objects i needed to store + 1 additional byte...
0
2437
by: kpoman | last post by:
Hi to all, I am trying to use some dll which needs some data types that I can't find in python. From the dll documentation, I am trying to use this: HRESULT IMKWsq::Compress ( VARIANT rawImage, short sizeX, short sizeY, VARIANT * wsqImage, short * result )
15
3730
by: khan | last post by:
Hi, I read that pointer representation can non-zero bit pattern, machine specific.Compiler when comes accross value '0' in pointer context, converts it to machine specific null pointer bit-pattern. My question is if a program refers to that specific value which is used by the machine to refer to null pointer, how compiler treats that?.
14
5012
by: dopiotr | last post by:
Hello Group, int Msg; MPI_Send(Msg, size, MPI_INT, DEST, TAG, MPI_COMM_WORLD); this is working fine. But how to send Msg declared like this: int *Msg=(int*)malloc(sizeof(int)*size); It gives me
0
7558
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7842
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5400
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5124
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3510
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
798
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.