datacontractserializer

DataContractSerializer, KnownType and inheritance

一世执手 提交于 2019-12-21 01:57:10
问题 I've read many articles about known types and i belive my example should work. But it doesn't. I'm getting the following exception on deserialization and don't understand why: Error in line 1 position 2. Expecting element 'A' from namespace 'http://schemas.datacontract.org/2004/07/ConsoleApplication2'.. Encountered 'Element' with name 'C', namespace 'http://schemas.datacontract.org/2004/07/ConsoleApplication2'. using System; using System.Runtime.Serialization; using System.Xml; using System

Events not working with after Deserialization

守給你的承諾、 提交于 2019-12-20 04:49:56
问题 PROBLEM: I have a Child class which uses DataContractSerialization and raises a Changed event when its Name property is set. <DataContract()> Public Class Child Public Event Changed() <DataMember()> Private _Name As String Public Sub New(ByVal NewName As String) _Name = NewName End Sub Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value RaiseEvent Changed() End Set End Property End Class It is contained within a Parent class which also uses

ExtensionDataObject not marked as serializable

与世无争的帅哥 提交于 2019-12-20 03:30:13
问题 Oi! I'm having issues serializing my session state. We have 2 components, our WCF and Web. Based on our AdministrationPartial.cs and Administration.svc we generate "Administration.cs" code for our web project with the following .bat file : svcutil.exe http://wcf_url.local/Administration.svc?wsdl /r:"{Path}\{Namespace}.dll" /d:"{Path}\{Namespace}\Code" I removed the personal data from the above statement and replaced it with {path} and {namespace}. The Administration.cs will be inside the Code

WCF data serialization : can it go faster?

穿精又带淫゛_ 提交于 2019-12-19 10:44:13
问题 This question is sort of a sequel to that question. When we want to build a WCF service which works with some kind of data, it's natural that we want it to be fast and efficient. In order to achieve that, we have to make sure all segments of data road trip work as fast as they could, from data storage back-end such as SQL Server, to a WCF client who requested that data. While seeking for an answer on that previous question, we have learned, thanks to Slauma and others who contributed through

NetDataContractSerializer vs DataContractSerializer

痞子三分冷 提交于 2019-12-19 06:14:10
问题 We have an application with objects that we'd like to keep serialized in the database. Currently we're using NetDataContractSerializer , but recently found out that due to the .Net types information involved, it creates huge files which means slow application, even for basic objects. We're considering switching to DataContractSerializer instead, and I've been looking for a nice comparison of the two but didn't find one. What's the difference in sizes between the objects created by the two? Is

NetDataContractSerializer vs DataContractSerializer

馋奶兔 提交于 2019-12-19 06:14:06
问题 We have an application with objects that we'd like to keep serialized in the database. Currently we're using NetDataContractSerializer , but recently found out that due to the .Net types information involved, it creates huge files which means slow application, even for basic objects. We're considering switching to DataContractSerializer instead, and I've been looking for a nice comparison of the two but didn't find one. What's the difference in sizes between the objects created by the two? Is

Why does WCF wrap request/response types in another XML element, and how to prevent this?

烈酒焚心 提交于 2019-12-19 03:25:22
问题 I have a simple echo service where I've defined one operation method and a pair of types for request/response: [ServiceContract(Name = "EchoService", Namespace = "http://example.com/services", SessionMode = SessionMode.NotAllowed)] public interface IEchoService { [OperationContract(IsOneWay = false, Action = "http://example.com/services/EchoService/Echo", ReplyAction = "http://example.com/services/EchoService/EchoResponse")] EchoResponse Echo(EchoRequest value); } The data types:

How can I make DataContractJsonSerializer serialize an object as a string?

人盡茶涼 提交于 2019-12-18 20:50:48
问题 I have a struct in C# that wraps a guid. I'm using DataContractJsonSerializer to serialize an object containing an instance of that class. When I was using a guid directly, it was serialized as a plain string, but now it's serialized as a name/value pair. Here's an NUnit test and supporting code that demonstrates the problem: private static string ToJson<T>(T data) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof (T)); using (MemoryStream ms = new MemoryStream()

XML Serialisation - When To Use DataContractSerializer / Binary / XMLSerialiser

為{幸葍}努か 提交于 2019-12-18 13:37:31
问题 I ve been looking at this for a while now It seems that binary serialisation is discouraged as any change to field names breaks serialisation =? Not Good XMLSerializer is problematic because you have to provide a no arg constructor and public fields although you do have more control over elements being attributes or elements and their naming DataContractSerializer is good but all suclassses need to be explicitly added which is a shame However I stumbled across NetDataContractSerializer which

Extension method to serialize generic objects as a SOAP formatted stream

感情迁移 提交于 2019-12-18 05:03:33
问题 I'm having a hard time trying to figure out a generic extension method that would serialize a given object as SOAP formatted. The actual implementation looks somewhat like this: Foobar.cs [Serializable, XmlRoot("foobar"), DataContract] public class Foobar { [XmlAttribute("foo"), DataMember] public string Foo { get; set; } [XmlAttribute("bar"), DataMember] public string Bar { get; set; } public Foobar() {} } Lipsum.cs [Serializable, XmlRoot("lipsum"), XmlType("lipsum"), DataContract] public