I have a WebAPI controller that I’m using with model classes with attributed properties to transform the C# naming to a more JavaScript like naming. e.g.
[DataMember(Name = "posInfo")]
public string PositionInformation { get; set; }
Everything works fine if I expose the values over the wire. Now I tried to call the controller on the server side to bootstrap some initial values at application startup. But if I call the controller locally the [DataMember] attributes are not “resolved”. Everything comes back with the C# named properties.
When does the [DataContract][DataMember] stuff kicks in and how to use it if I call my controller locally?
DataMember will be used when your object is de/serialized. So, if you are sending your object over the wire using web-api, your client should be receiving the property as posInfo. If you are referencing your object locally via .net (for example, in a library or a project reference), then you will be referring to the property by its name PositionInformation.
Depending on the type of serialization that you are performing, it is possible that this property is not being translated or that the DataMember attribute is not supported. FWIW, the built-in XML and JSON serializers for Web API support the DataMember and DataContract attributes.
More information on how the DataMember attribute works can be found at the MSDN site.