datacontractserializer

DataContract Serialization without DataMember Attribute

泄露秘密 提交于 2020-01-05 04:36:06
问题 I have the following XML generated using a function FreezeAllAccountsForUser. I need to serialize only the following two columns for this function. How can I restrict the serialization to two columns? BankAccountID Status Note: The key point is that the scope of making this restriction should be only within the function FreezeAllAccountsForUser; not global . REFERENCE Serializing IEnumerable Containing Derived classes: Circular Reference Issue XML <ArrayOfBankAccount xmlns:i="http://www.w3

XmlDictionaryReader reading fixed-size zeroed Stream

ぃ、小莉子 提交于 2020-01-04 12:48:57
问题 Can someone give me good explanation why this has to fail? const int bufferSize = 2 * 1024, testValue = 123456; var buffer = new byte[bufferSize]; var serializer = new DataContractSerializer(typeof(int)); //Serialize value using (var memStream = new MemoryStream(buffer)) using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(memStream)) serializer.WriteObject(writer, testValue); //Deserialize value using (var memStream = new MemoryStream(buffer)) using (XmlDictionaryReader

XmlDictionaryReader reading fixed-size zeroed Stream

我怕爱的太早我们不能终老 提交于 2020-01-04 12:48:53
问题 Can someone give me good explanation why this has to fail? const int bufferSize = 2 * 1024, testValue = 123456; var buffer = new byte[bufferSize]; var serializer = new DataContractSerializer(typeof(int)); //Serialize value using (var memStream = new MemoryStream(buffer)) using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateBinaryWriter(memStream)) serializer.WriteObject(writer, testValue); //Deserialize value using (var memStream = new MemoryStream(buffer)) using (XmlDictionaryReader

Rename __type-field in WCF services

你说的曾经没有我的故事 提交于 2020-01-04 06:27:09
问题 I'm trying to map GeoJSON to DataContracts for use in some WCF-services at work. GeoJSON has a field called "type" and the DataContracts-serialization depends on the field " _ _type" to support de/serializing to the correct subtypes. My DataContracts are all named after the GeoJSON spec and I've set the Namespace of the DataContracts to "", so basically I have managed to implement GeoJSON <==> DataContracts if only i could tell the (de)serializer to use the field "type" instead of the field "

Why are attributes not supported with the DataContractSerializer?

爷,独闯天下 提交于 2020-01-03 21:09:10
问题 I create xsd's based upon client's documentation and all of the xsd's have attributes. I have been using xsd.exe to generate the classes from the xsd's, but I read that attributes aren't supported for the DataContractSerializer. Why not? Does this mean that I can only have an soap+xml file with just elements? This is not possible because I don't create the requests. Is there a way to specify to svcutil to recognize attributes? 回答1: DataContractSerializer was created with a "code-first"

Wcf DataContract class with enum causes “'Enum value '-1' is invalid for type” error

主宰稳场 提交于 2020-01-03 20:15:56
问题 I'm getting the following exception trying to pass an object through wcf: There was an error while trying to serialize parameter http://tempuri.org/:item. The InnerException message was 'Enum value '-1' is invalid for type 'Models.SubModels.DamageLocations' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'. Please see InnerException for more details. It is defined like

Wcf DataContract class with enum causes “'Enum value '-1' is invalid for type” error

孤者浪人 提交于 2020-01-03 20:15:06
问题 I'm getting the following exception trying to pass an object through wcf: There was an error while trying to serialize parameter http://tempuri.org/:item. The InnerException message was 'Enum value '-1' is invalid for type 'Models.SubModels.DamageLocations' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'. Please see InnerException for more details. It is defined like

DataContractSerializer not Serializing member of class that inherits ISerializable

半腔热情 提交于 2020-01-03 15:22:09
问题 I have this class: using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace Grouping { [Serializable] public class Group<T> : HashSet<T> { public Group(string name) { this.name = name; } protected Group(){} protected Group(SerializationInfo info, StreamingContext context):base(info,context) { name = info.GetString("koosnaampje"); } public override void GetObjectData(SerializationInfo info,StreamingContext context) { base.GetObjectData(info,context); info

How to set the StreamingContext for DataContractSerializer?

ぃ、小莉子 提交于 2020-01-03 13:10:06
问题 I have some code something like this: [DataContract] class Foo { [OnSerializing] private void BeforeSerialize(StreamingContext ctx) { ((MtType)ctx.Context).DoStuff() } ... } var reader = new XmlTextReader(filename); var serializer = new DataContractSerializer(typeof(Type)); Type type = (Type)serializer.ReadObject(reader); and I need to provide the StreamingContext structure. I have found several references that this can be done for NetDataContractSerializer but none for DataContractSerializer

How to set the StreamingContext for DataContractSerializer?

情到浓时终转凉″ 提交于 2020-01-03 13:09:33
问题 I have some code something like this: [DataContract] class Foo { [OnSerializing] private void BeforeSerialize(StreamingContext ctx) { ((MtType)ctx.Context).DoStuff() } ... } var reader = new XmlTextReader(filename); var serializer = new DataContractSerializer(typeof(Type)); Type type = (Type)serializer.ReadObject(reader); and I need to provide the StreamingContext structure. I have found several references that this can be done for NetDataContractSerializer but none for DataContractSerializer