How To Ignore Case Sensitive Properties Name In Wcf Service Call?
Hello I wonder about possibility to call WCF method from client side what would be ignore case sensitive properties names (on client side I am working with JSON with lowercase prop
Solution 1:
You can use the Name
property of the [DataMember]
attribute to map the property name:
[DataContract]
publicclassUser : ICloneable
{
[DataMember(Name = "login")]
[JsonProperty(PropertyName = "login")]
[StringLength(40, ErrorMessage = "The Login value cannot exceed 40 characters. ")]
[DefaultValue("")]
public String Login { get; set; }
[DataMember(Name = "id")]
[JsonProperty(PropertyName = "id")]
publicint UserId { get; set; }
}
Update following comment: There isn't any knob you can use to enable case-insensitive deserialization on the default serializer used by WCF. There are some options (none ideal), though. You can change the serializer to use JSON.NET (which can be done, see this blog post, but not very easily) and use the serializer settings in that serializer to ignore casing. I think you should also be able to add additional properties (which can be private, except if the application is running in partial trust), to map the additional supported cases; something similar to the code below:
[DataContract]
publicclassUser
{
[DataMember]
public String Login { get; set; }
[DataMember]
private String login { get { returnthis.Login; } set { this.Login = value; } }
[DataMember]
publicint UserId { get; set; }
[DataMember]
privateint id { get { returnthis.UserId; } set { this.UserId = value; } }
}
Post a Comment for "How To Ignore Case Sensitive Properties Name In Wcf Service Call?"