Why DataMember attribute is applying on class fields rather than Properties in WCF, I am using the Serialization
-
Hi All, Can any one tell why the DataMember attribute is applying on class fields rather than Properties in WCF, I am using the Serialization. Service Code: [System.Runtime.Serialization.DataContract(Namespace = "http://QuickReturns")] public partial class OTA_HotelAvailGetRQHotelAvailRequestDateRange { private string startField; [System.Runtime.Serialization.DataMember(Name = "Start")] public string Start { get{} set{} } } Client Side : OTA_HotelAvailGetRQHotelAvailRequestDateRange dataRange= new OTA_HotelAvailGetRQHotelAvailRequestDateRange(); dataRange.startField= "10"; Thanks and Regards
-
Hi All, Can any one tell why the DataMember attribute is applying on class fields rather than Properties in WCF, I am using the Serialization. Service Code: [System.Runtime.Serialization.DataContract(Namespace = "http://QuickReturns")] public partial class OTA_HotelAvailGetRQHotelAvailRequestDateRange { private string startField; [System.Runtime.Serialization.DataMember(Name = "Start")] public string Start { get{} set{} } } Client Side : OTA_HotelAvailGetRQHotelAvailRequestDateRange dataRange= new OTA_HotelAvailGetRQHotelAvailRequestDateRange(); dataRange.startField= "10"; Thanks and Regards
The attribute is applied to the Start property, not the startField field. Attributes are placed above the method, class... they describe. But having the DataMember attribute for a field is not wrong. Since you'd be telling WCF that the value of the field is to be serialized. But in your code, the only DataMember attribute is applied to the property.
Eslam Afifi
-
Hi All, Can any one tell why the DataMember attribute is applying on class fields rather than Properties in WCF, I am using the Serialization. Service Code: [System.Runtime.Serialization.DataContract(Namespace = "http://QuickReturns")] public partial class OTA_HotelAvailGetRQHotelAvailRequestDateRange { private string startField; [System.Runtime.Serialization.DataMember(Name = "Start")] public string Start { get{} set{} } } Client Side : OTA_HotelAvailGetRQHotelAvailRequestDateRange dataRange= new OTA_HotelAvailGetRQHotelAvailRequestDateRange(); dataRange.startField= "10"; Thanks and Regards
kalyan_vb wrote:
why the DataMember attribute is applying on class fields rather than Properties in WCF
I'm not quite sure what you're asking here, but keep in mind the serializer you use will also determine if the data contract attributes are honored or not. For example, the BinaryFormatter "serializes public and private fields of a type". You haven't shown what serializer you are using.
Mark Salsbery Microsoft MVP - Visual C++ :java: