Tutorial :WCF: why do I have to set [field]specified manually to send value to server?



Question:

I generated WCF proxy that has integer [fieldName] in message contract request class. I tried to send value to server but value always came 0 until I manually set [fieldNameSpecified] to true.

Is there something wrong with proxy generation or WCF was designed this way? What are the reasons behind [Specified] fields especially if string/guids have no specified fields in proxy classes?

Thank you in advance


Solution:1

It's because the Xml Serializer was never updated to support Nullable, so the way it dealt with optional fields using value types (say, an int, which can't be set to null) was to have a XxxSpecified boolean field alongside it that allowed you to tell the serializer whether to consider the value for the corresponding field or not during serialization.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »