6

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!

Shlo
  • 1,036
  • 2
  • 10
  • 23

1 Answers1

6

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Dear marc_s i appriciate you reply! my model contains only data member int and i don't have a bool property that define if I have a value to it. did I understand you correctly? if so, it does not solve my problem. – Shlo Jun 12 '12 at 14:20
  • @Shlo: what does the data class look like that gets created when you add the service reference to your WCF client app? It's not the data contract that you wrote that you need to look at - you need to look at the data class that's been automatically generated on the client that consumes your WCF service – marc_s Jun 12 '12 at 14:30
  • 1
    YOU ARE RIGHT!!! THANK YOU! I didn't look at the class that gets created after adding the service reference... – Shlo Jun 12 '12 at 14:53