2

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.

Community
  • 1
  • 1
Brikesh Kumar
  • 149
  • 1
  • 12
  • You already found the answer, at http://stackoverflow.com/questions/8993507/data-member-default-values-how-to-figure-out-whether-something-was-really-sent. – carlosfigueira Apr 10 '13 at 06:40
  • I tried that approach, but it returns a stackoverflow exception while trying to deserialize. – Brikesh Kumar Apr 10 '13 at 16:14
  • That solution works. Make sure you're not setting the **property** (instead of the **field**) on the property setter. – carlosfigueira Apr 10 '13 at 16:18
  • @carlosfigueiraless : thanks a ton. I had Camel case names for fields and Pascal case for properties. And wasn't spotting the typo. But there's another problem the python client omits that property that user doesn't specify. so it works as expected for python client. But the C# client doesn't omit, it sends the soap message with field and sets the nil attribute to true. so this doesn't work with C# client. I'll have figure out something for C# or similar client which doesn't omit the field in soap message – Brikesh Kumar Apr 11 '13 at 02:49

1 Answers1

3

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

DarkSquirrel42
  • 10,167
  • 3
  • 20
  • 31