Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int properties are 0 when consuming WCF in .Net 2

Tags:

wcf

I have an MVC project in .Net 4 with WCF service with BasicHttpBinding.

When consuming this service in .Net 2 the values that arriving if the property is int are 0.

if it is a string, than it goes fine.

bulding a new project in .Net 4 consuming the same service and using the exact implementation (as the .Net 2) ==> the int values are correct.

WHY?

Thanks!

like image 315
Shlo Avatar asked Jun 12 '12 13:06

Shlo


1 Answers

I bet you have a data contract that has the actual int property:

public int YourProperty ......

as well as a YourPropertySpecified property along side it:

public bool YourPropertySpecified ......

Since an int cannot be null, WCF cannot distinguish whether or not you have defined a value - you need to tell it.

So if you use an int property and set a value to it - you also need to set its accompanying YourPropertySpecified property to true:

yourData.YourProperty = 42;
yourData.YourPropertySpecified = true;

With this extra step, the int values should arrive at the server just fine

like image 83
marc_s Avatar answered Nov 09 '22 03:11

marc_s