datamember

Serialization DataMember (name) override issue

穿精又带淫゛_ 提交于 2019-12-01 14:14:16
问题 I am using a DataContractJsonSerializer and have an issue with the DataMember Name. I made a base class and several derived classes. I need the derived classes because I have different json strings. I want to deserialize the json strings and therefore need different names for the datamembers. I try to change the DataMember name as in the following example: Baseclass: [DataContract] public abstract class BaseClass { [DataMember] public virtual string FirstMethod { get; protected set; } }

Why is using [DataMember(EmitDefaultValue = false)] not recommended?

无人久伴 提交于 2019-11-30 13:36:56
问题 In WCF you can define a contract using the [DataContract] and [DataMember] attributes, like this: [DataContract] public class Sample { [DataMember(EmitDefaultValue = false, IsRequired = false)] public string Test { get; set; } } This article on the MSDN states that using EmitDefaultValue = false is not recommended: However, i like to use this, because the XML that is generated using this construction is cleaner. Not specifying this setting results in: <Sample> <Test xsi:nil="true"/> </Sample>

Why is using [DataMember(EmitDefaultValue = false)] not recommended?

自闭症网瘾萝莉.ら 提交于 2019-11-30 07:54:39
In WCF you can define a contract using the [DataContract] and [DataMember] attributes, like this: [DataContract] public class Sample { [DataMember(EmitDefaultValue = false, IsRequired = false)] public string Test { get; set; } } This article on the MSDN states that using EmitDefaultValue = false is not recommended: However, i like to use this, because the XML that is generated using this construction is cleaner. Not specifying this setting results in: <Sample> <Test xsi:nil="true"/> </Sample> while using the setting the element is ommited when there is no value: <Sample> </Sample> I'm curious

DataMember attributes for Data validation

时光怂恿深爱的人放手 提交于 2019-11-30 07:18:40
I am looking to place attributes on my WCF data contract members to validate string length and possibly use regex for more granular parameter validation. I can the [Range] attribute for numeric and DateTime values and was wondering if any of you have found any other WCF Data Member attributes I can use for data validation. I have found a bevvy of attributes for Silverlight but not for WCF. Add System.ComponentModel.DataAnnotations reference to your project. The reference provides some DataAnnotations which are: RequiredAttribute, RangeAttribute, StringLengthAttribute,

WCF: is there an attribute to make parameters in the OperationContract required?

自闭症网瘾萝莉.ら 提交于 2019-11-29 10:22:27
I use [DataMember(IsRequired=true)] to make the DataContract properties required. There doesn't seem to be some IsRequired for the OperationContract parameters. How do I make them required and not allow null? The parameter in of OperationContract appears to be optional in SoapUI tool. Though this must never be optional or null. WCF Interface: [OperationContract] IsClientUpdateRequiredResult IsClientUpdateRequired(IsClientUpdateRequiredInput versie); ... [DataContract] public class IsClientUpdateRequiredInput { [DataMember(IsRequired=true)] public string clientName { get; set; } [DataMember

DataMember attributes for Data validation

会有一股神秘感。 提交于 2019-11-29 09:19:05
问题 I am looking to place attributes on my WCF data contract members to validate string length and possibly use regex for more granular parameter validation. I can the [Range] attribute for numeric and DateTime values and was wondering if any of you have found any other WCF Data Member attributes I can use for data validation. I have found a bevvy of attributes for Silverlight but not for WCF. 回答1: Add System.ComponentModel.DataAnnotations reference to your project. The reference provides some

WCF: is there an attribute to make parameters in the OperationContract required?

家住魔仙堡 提交于 2019-11-28 03:32:51
问题 I use [DataMember(IsRequired=true)] to make the DataContract properties required. There doesn't seem to be some IsRequired for the OperationContract parameters. How do I make them required and not allow null? The parameter in of OperationContract appears to be optional in SoapUI tool. Though this must never be optional or null. WCF Interface: [OperationContract] IsClientUpdateRequiredResult IsClientUpdateRequired(IsClientUpdateRequiredInput versie); ... [DataContract] public class

WCF: Exposing readonly DataMember properties without set?

拈花ヽ惹草 提交于 2019-11-27 00:36:16
I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I'd like to make available through a property. However, I'm unable to do so because it doesn't seem that I'm allowed to add a [DataMember] property without having both get and set. So - is there a way to have a [DataMember] property without setter? [DataContract] class SomeClass { private readonly int _id; public SomeClass() { .. } [DataMember] public int Id { get { return _id; } } [DataMember] public string SomeString { get; set; } } Or will the solution be use

WCF: Exposing readonly DataMember properties without set?

假装没事ソ 提交于 2019-11-26 22:13:42
问题 I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I'd like to make available through a property. However, I'm unable to do so because it doesn't seem that I'm allowed to add a [DataMember] property without having both get and set. So - is there a way to have a [DataMember] property without setter? [DataContract] class SomeClass { private readonly int _id; public SomeClass() { .. } [DataMember] public int Id {

Configure JSON.NET to ignore DataContract/DataMember attributes

六月ゝ 毕业季﹏ 提交于 2019-11-26 06:43:20
问题 We are running into a situation on an MVC3 project with both the Microsoft JSON serializers and JSON.NET. Everybody knows DateTime\'s are basically broken in Microsoft\'s serializers, so we switched to JSON.NET to avoid this issue. That works great, except that some of the classes we are trying to serialize are POCOs with DataContract/DataMember attributes. They are defined in an assembly that is referenced in multiple places. Additionally, they have some other display properties that are not