datacontract

EmitDefaultValue=false only working for strings

折月煮酒 提交于 2021-02-11 17:57:20
问题 I am trying to serialize the following c# class to XML [DataContract] public class LatLonPoint { [DataMember(IsRequired = true, Order = 1)] public float Lat { get; set; } [DataMember(IsRequired = true, Order = 2)] public float Lon { get; set; } [DataMember(EmitDefaultValue = false, Order = 3)] public DateTime? OptimalTime { get; set; } } When I serialize this class using the following code public static string GetLatLonPointXml(LatLonPoint data) { XmlSerializer xmlSerializer = new

Custom Element Names using the DataContractSerializer on a List of primitives

こ雲淡風輕ζ 提交于 2021-02-04 14:52:07
问题 I'm interested about the best way to go about setting custom element names when using List of primitives with the DataContractSerializer. Let's say I have the following class which contains a List of Strings as a DataMember. [DataContract] public class ClassName { [DataMember] public List<String> FieldName { get; set; } } By default, this serializes to the following: <ClassName xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <FieldName xmlns:a="http://schemas.microsoft.com/2003/10

CollectionDataContract serialization not adding custom properties (DataMember)

冷暖自知 提交于 2021-01-29 02:54:31
问题 We have a legacy system that needs to be fed (XML) data in a most unstructured format. Is the following even possible with the .NET DataContractSerializer ? Given the following DataContracts [CollectionDataContract(Name = "Options", ItemName = "Option")] public class OptionItemCollection : List<OptionItem> { [DataMember(Name = "Name")] public string Name { get; set; } public OptionItemCollection() { } public OptionItemCollection(IEnumerable<OptionItem> items) : base(items) { } } [DataContract

Renaming of class property that is marked with a DataMemberAttribute

老子叫甜甜 提交于 2020-01-30 07:53:07
问题 Actually i have a class like this [DataContract] public class Item : IExtensibleDataObject { [Browsable(false)] public virtual ExtensionDataObject ExtensionData { get; set; } [DataMember] public string ID { get; set; } [DataMember] public string Name { get; set; } public Item() : this(String.Empty, String.Empty) { } public Item(string id, string name) { ID = id ?? String.Empty; Name = name ?? String.Empty; } } You can easily serialize and deserialize it. But now comes the hard part: I have to

DataContract not able to serialize collection members

两盒软妹~` 提交于 2020-01-30 05:26:13
问题 I have data that is best described as "onion-like" in that each outer layer builds on the one below it. Below you will see a vastly simplified version (mine is several layers deeper but exhibits the same behavior at each level). [CollectionDataContract] public abstract class AbstractTestGroup : ObservableCollection<AbstractTest> { [DataMember] public abstract string Name { get; set; } } [CollectionDataContract] [KnownType(typeof(Test))] public class TestGroup : AbstractTestGroup { public

In a WCF proxy-generated client, what determines the serializer used?

筅森魡賤 提交于 2020-01-25 05:20:29
问题 When I expose a WCF service using DataContact/DataMember attributes, each service reference I make in other projects to this service generates classes with DataContract/DataMember attributes (as well as IExtensibleDataObject interface implementation, etc.). In another project, I have to use a SOAP service whose WSDL has not been generated by WCF, but by some other tool I don't know and can't change the behavior. My problem is that the code generated by my svcutil proxy is a little bit less

Contract-First WCF SOAP development: controlling over primitive types XML serialization

China☆狼群 提交于 2020-01-17 08:44:10
问题 I am implementing C# WCF SOAP 1.1 service (server-side) from a given wsdl (contract first development). The problem I am facing is that there are additional (non-wsdl) formatting requirements for xsd:dateTime, xsd:decimal and xsd:time. Contract generated by SvcUtil.exe performs standard XML serialization formatting dates and decimals a bit differently. Given the sample SOAP messages provided my WCF service stub has no problems understanding and converting these formats. My responses however

Contract-First WCF SOAP development: controlling over primitive types XML serialization

帅比萌擦擦* 提交于 2020-01-17 08:44:09
问题 I am implementing C# WCF SOAP 1.1 service (server-side) from a given wsdl (contract first development). The problem I am facing is that there are additional (non-wsdl) formatting requirements for xsd:dateTime, xsd:decimal and xsd:time. Contract generated by SvcUtil.exe performs standard XML serialization formatting dates and decimals a bit differently. Given the sample SOAP messages provided my WCF service stub has no problems understanding and converting these formats. My responses however

Why am I using the KnownType attribute wrong?

筅森魡賤 提交于 2020-01-13 11:23:22
问题 I am trying to deserialize a json response from a google api, so i thought i would define a couple classes to help with it: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name="language")] public string Language { get; set; } [DataMember(Name="isReliable")] public bool IsReliable { get; set; } [DataMember(Name="confidence")] public double Confidence {get;set;} } [DataContract] public abstract class ResponseData { [DataMember(Name = "error")] public TranslationError

Why am I using the KnownType attribute wrong?

浪子不回头ぞ 提交于 2020-01-13 11:23:08
问题 I am trying to deserialize a json response from a google api, so i thought i would define a couple classes to help with it: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name="language")] public string Language { get; set; } [DataMember(Name="isReliable")] public bool IsReliable { get; set; } [DataMember(Name="confidence")] public double Confidence {get;set;} } [DataContract] public abstract class ResponseData { [DataMember(Name = "error")] public TranslationError