datacontract

Silverlight client, datacontract, and private readonly members

懵懂的女人 提交于 2019-12-13 02:59:25
问题 I have a Silverlight client and a WCF service that I want to have share a class: [DataContract] public class DatesAreFun { [DataMember] private readonly DateTime _date; [DataMember] private readonly bool _isFun; public DateTime DateTime { get { return _date; } } public bool IsFun { get { return _isFun; } } public DatesAreFun(DateTime date, bool isFun) { _date = date; _isFun = fun; } } The WCF side seems to send the appropriate data across the wire just fine, but the Silverlight side doesn't

Using custom DataContractResolver with multiple assemblies

限于喜欢 提交于 2019-12-13 02:00:34
问题 I have following setup in a MEF application: Assembly MyBaseAssembly : namespace My.Namespace { [DataContract] public class Container { [DataMember] public Data Item { get; set; } } [DataContract] public class Data { [DataMember] public string Foo { get; set; } } } Assembly SecondAssembly , references the MyBaseAssembly : namespace My.Another.Namespace { [DataContract] public class SecondData : Data { [DataMember] public string Bar { get; set; } } } Somewhere deep inside of my application I

Custom serialisation of a Dictionary in a DataContract

∥☆過路亽.° 提交于 2019-12-12 14:24:45
问题 Basically I have a DataContract which contains a Dictionary : [DataContract] public class MyDictionary : IDictionary<string, object> { [DataMember(Name = "Data")] protected IDictionary<string, object> Dictionary { get; private set; } // ... } Here is the relevent part of the XML output: <Data> <a:KeyValueOfstringanyType> <a:Key>ID</a:Key> <a:Value i:type="s:int">2</a:Value> </a:KeyValueOfstringanyType> <a:KeyValueOfstringanyType> <a:Key>Value</a:Key> <a:Value i:type="s:int">4711</a:Value> </a

How to set [DataMember] on all class members

馋奶兔 提交于 2019-12-12 13:24:20
问题 I have a class with countless members. I want to use DataContract serialization/deserialization and so the class has the [DataContract] attribute. If I put the [DataMember] attribute that works otherwise it doesn't. Am I to put [DataMember] on all of them? Isn't there a way to automatically set ALL of them as datamembers? Thanks --EDIT-- The solution in Set DataContract and DataMember Without All the Attributes is not working. public Test() { if (false) { MyClass theclass = new MyClass(); var

Cant deserilize derived class. But it works if it's in a list or a dictionary. Any thoughts?

三世轮回 提交于 2019-12-12 04:15:46
问题 I got a weird problem where I can serialize a derived class if I put it in a List but not when it stands on it own. I am using these methods to serialize and deserialize (found them here): public static string Serialize(T obj) { using (MemoryStream memoryStream = new MemoryStream()) using (StreamReader reader = new StreamReader(memoryStream)) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); serializer.WriteObject(memoryStream, obj); memoryStream.Position = 0;

F# Multiple Attributes CLIMutable DataContract

血红的双手。 提交于 2019-12-12 03:59:13
问题 I am running into an issue with combining attributes when using ServiceStack.Redis with f#. Maybe I am thinking about this wrong but right now I'd like my type to be seralized to JSON but also passable to ServicvStack. The issue with f# types is that there is no default constructor and this the data added to my Redis instance is emtpy, well the record is there but none of the data inside it is there. Here is an example: open System open ServiceStack.Redis [<CLIMutable>] [<DataContract>] type

Protobuf .NET serialization for inheritance classes

时光总嘲笑我的痴心妄想 提交于 2019-12-11 12:24:03
问题 I'm trying to migrate my code serializer from NetDataContract to Protobuf.Net. Let's consider the following class example to help the understanding: [DataContract(Name "a", IsReference = true)] class Test { [DataMember(Name = "a")] public int Id { get; set; } [DataMember(Name = "b")] public string Name { get; set; } } To be able to use Protobuf .NET using DataContract, I'm using the following options: RuntimeTypeModel.Default.InferTagFromNameDefault = true; RuntimeTypeModel.Default

WCF service multiple method calls one ajax request

若如初见. 提交于 2019-12-11 10:21:44
问题 Before I begin my question a little background info. I have the WCF service that is being called via jquery.ajax . I can see in the console window and verify with other tools that the request is happening only once. On the server side, I see the method firing 3 times exactly. How could this happen? On the service I am decorating with the following attributes and signature [OperationContract] [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public

How to configure ServiceStack.Text to use EnumMember when serializing to csv or jsv?

时间秒杀一切 提交于 2019-12-11 06:55:18
问题 This is a follow up question to my earlier question about ServiceStack.Text and deserializing json to .Net enums. The answer to that question resolves how to get ServiceStack.Text to use .Net DataContract and EnumMember to map strings to enum values. Now I am trying to serialize the same enums to various formats and while json serialization is working in a round-trip way as expected, both csv and jsv conversion are ignoring the data contract. Is there a way to configure ServiceStack.Text

ServiceStack.Text: Forcing serialization of a property not decorated with DataMember attribute

…衆ロ難τιáo~ 提交于 2019-12-11 06:27:32
问题 I have the following class (simplified). [DataContract] public class ServiceResponse { public int Sequence { get; set; } [DataMember] public ServiceResponseStatus Status { get; set; } } I'm using ServiceStack to serialize objects for logging purposes, and letting DataContractSerializer do the rest. ServiceStack, as expected, will not serialize Sequence as it is not decorated with a DataMember attribute. Is there a way to force ServiceStack to serialize this property? Marc Gravell's answer to