Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Why DataMember attribute is applying on class fields rather than Properties in WCF, I am using the Serialization

Why DataMember attribute is applying on class fields rather than Properties in WCF, I am using the Serialization

Scheduled Pinned Locked Moved WCF and WF
csharpwcfjson
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalyan_vb
    wrote on last edited by
    #1

    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

    E M 2 Replies Last reply
    0
    • K kalyan_vb

      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

      E Offline
      E Offline
      Eslam Afifi
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • K kalyan_vb

        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

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups