datacontractserializer

C# DataContractSerializer SerializationException with Enum set in object field

試著忘記壹切 提交于 2019-12-06 15:44:58
Given the following code, [DataContract] public class TestClass { [DataMember] public object _TestVariable; public TestClass(object value) { _TestVariable = value; } public void Save() { using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(new FileStream("test.tmp", FileMode.Create))) { DataContractSerializer ser = new DataContractSerializer(typeof(TestClass)); ser.WriteObject(writer, this); } } } public enum MyEnum { One, Two, Three } Why does it fail to serialize when _TestVariable is set to an Enum value? new TestClass(1).Save(); // Works new TestClass("asdfqwer").Save()

Using the WCF DataContractJsonSerializer in .NET 3.5

心已入冬 提交于 2019-12-06 13:43:38
I'm trying to use the geocoding code from here in my ASP.NET MVC 2 site. Unfortunately, some of that code, specifically the DataContractJsonSerializer usage, is only possible through .NET 4.0 . As my hosting provider doesn't support .NET 4, I'm forced to implement that functionality in .NET 3.5. How can I rework the code (which I have reposted below) to work in .NET 3.5? The Google Maps Geocoding API can also return XML, if that's easier to serialize in 3.5... Below is the code I'm trying to convert from .NET 4 to .NET 3.5: using System; using System.Runtime.Serialization; using System.Runtime

Why needs DataContractSerializer alphabetically sorted XML?

梦想与她 提交于 2019-12-06 09:46:36
问题 I have following data contract: namespace Wcf.Contracts.Data { [DataContract] public class Presence { [DataMember] public int Id { get; set; } [DataMember] public DateTime? From { get; set; } [DataMember] public DateTime? To { get; set; } [DataMember] public TimeSpan? BreakPeriod { get; set; } } } Serializing an instance of Presence to XML and deserializing the same XML back to an instance of Presence works well. But deserializing a string variable which represents a serialized Presence

XmlSerializer vs DataContractSerializer

China☆狼群 提交于 2019-12-06 08:52:48
问题 I just realized that DataContractSerializer expects nodes in the alphabetical order or the specified order. Is there any way i could make it NOT do it? TIA 回答1: I don't think so. You may find the discussion on this question informative: Ignore field order in DataContractSerializer 回答2: I used IDispatchMessageInspector.AfterReceiveRequest to intercept the message and sort it alphabetically. 来源: https://stackoverflow.com/questions/3570729/xmlserializer-vs-datacontractserializer

Why can't I serialize an object using DataContractSerializer?

我是研究僧i 提交于 2019-12-06 07:49:49
问题 I'm trying to serialize a type using the DataContractSerializer and am getting the exception below. This isn't for an SOA service, but I would still like to use the DataContractSerializer if possible. I am using .Net 3.5 SP1. Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Add any types not known statically to the list of known types - for example, by

Serialization / Derialization of a tree structure

↘锁芯ラ 提交于 2019-12-06 03:29:43
问题 I'm trying to figure out the best way to save (serialize) and later open (deserialize) a tree structure. My structure is made up of various object types with different properties, but each inherits from a base abstract "Node" class. Each node has unique ID (GUID), and has an AddSuperNode(Node nd) method that will set the parent of a node. This in turn calls other methods that allow the parent node to know what sub nodes it has. However, some nodes also utilize a AddAuxSuperNode() method that

Adding a DataMember to a different namespace to the DataContract

邮差的信 提交于 2019-12-06 03:03:29
With the XmlSerializer I can have my members in different namespaces to the parent type. Can I do the same thing with DataContractSerializer ? I would like the following XML: <h:Type xmlns:h="http://schemas.e.com/WebServices" xmlns="http://schemas.e.com/WebServices"> <Member xmlns="http://schemas.e.com/CoreTypes">0</Member> </h:Type> Is this possible in with DataContractSerializer ? nitzmahone You can define subdatacontracts in different namespaces and use them as members of another datacontract, but you can't control the individual member names and/or shapes. The DataContractSerializer isn't

Forcing ASMX proxy to use XmlSerializer instead of DataContractSerializer

∥☆過路亽.° 提交于 2019-12-05 21:01:13
We were given external SOAP services that we have to consume in our project. All of these provide WSDL data, but a lot of them are not .NET services (most of them were written in Java). We have generated a number of client proxies with wsdl.exe tool. This tool does what it's supposed to do, it creates proxies for us to consume. The problem appears once we try to call methods on these services using generated proxies. We intercept all SOAP requests for logging purposes and XML data looks different from the one specified in WSDL schema. For instance, if a field is called "Name", our proxies will

WCF service dataContractSerializer maxItemsInObjectGraph in web.config

£可爱£侵袭症+ 提交于 2019-12-05 20:43:34
问题 I am having issues specifying the dataContractSerializer maxItemsInObjectGraph in host's web.config. <behaviors> <serviceBehaviors> <behavior name="beSetting"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="True" /> <dataContractSerializer maxItemsInObjectGraph="2147483646"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="MyNamespace.MyService" behaviorConfiguration="beSetting" > <endpoint address="http://localhost/myservice/"

WCF DataContractSerializer doesn't pick up contract attributes… why not?

随声附和 提交于 2019-12-05 02:00:04
问题 I have the following type which I use as a message contract in WCF: [MessageContract(IsWrapped = true, WrapperNamespace = "http://example.com/services", WrapperName = "EchoRequest")] public class EchoRequest { public EchoRequest() { } public EchoRequest(String value) { Value = value; } [MessageBodyMember(Name = "Value", Namespace = "http://example.com/services", Order = 0)] public String Value { get; set; } } When I generate a proxy to this type using svcutil.exe , I get a client which is