Brikesh Kumar
Brikesh Kumar

Reputation: 149

How to differentiate between user specified null and default value in WCF data contract

I need to define a WCF API to enable user to update large object. While I can define few smaller methods and let the user update specific parts of the large object at a time. But for some reason I am not able to do that. The other way I tried is defined the data contract as collection of key-value (key is an enum and value is some string) and let the user add whatever he wants to update. This api very compact but it's not very intuitive and can be confusing for the user. Also since the value is of string type, so it's not very type safe.

So I now I have create one api, where the user can update the entire object. for example:

public UpdateResult UpdateAPI(UpdateParam param){}

Now the UpdateParam class will several nullable fields.

Q: If there is a null value in one of the fields, how can differentiate at the server side, the null value was specified by the user or it's default non-specified one? Is there something in the incoming soap message that can help differentiate?

Any help would be greatly appreciated.

Similar questions asked are 1. Data member default values, how to figure out whether something was really sent? 2.

Upvotes: 2

Views: 412

Answers (1)

DarkSquirrel42
DarkSquirrel42

Reputation: 10257

no, as far as i know there is no way to tell the conditions apart if you only have a nullable field ...

however, you could provide an additional bool per property that could serve as a flag to indicate if the value was set by the user or is still on its default value

You can implement the setters of your properties to automatically set the corresponding bool when your properties are set

Upvotes: 3

Related Questions