Int properties are 0 when using WCF in .Net 2

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

When using this service in .Net 2, the values ​​that arrive if the property is int are 0.

if it is a string, than this is normal.

creating a new project in .Net 4 using the same service and using an exact implementation (like .Net 2) ==> int values ​​are correct.

Why?

Thanks!

+6
source share
1 answer

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

 public int YourProperty ...... 

as well as the YourPropertySpecified property next to it:

 public bool YourPropertySpecified ...... 

Since int cannot be null, WCF cannot tell if you have defined a value or not, you need to say that.

So, if you use the int property and set the value for it, you also need to set the accompanying property YourPropertySpecified to true:

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

With this extra step, int values ​​should appear on the server just fine

+6
source

Source: https://habr.com/ru/post/917889/


All Articles