Questions tagged [datacontract]

A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. A data contract precisely defines, for each parameter or return type, what data is serialized to be exchanged.

798 questions
5
votes
2 answers

Decoding a Java/JSON Map into an F# object

I'm having trouble converting a Java/JSON map into a usable F# object. Here's the heart of my code: member this.getMapFromRpcAsynchronously = Rpc.getJavaJSONMap (new Action<_>(this.fillObjectWithJSONMap)) () member…
Mike Cialowicz
  • 9,892
  • 9
  • 47
  • 76
5
votes
0 answers

Stop DataContractSerializer putting in namespace?

I want to serialize datacontract classes into XMl, but without the Namespaces. I've added: [DataContract(Namespace="")] but I still get: Mr ... Is there any way…
BlueChippy
  • 5,935
  • 16
  • 81
  • 131
5
votes
1 answer

Serialization with JsonConvert Loses Data

I'm using JsonConvert in my project in order to make a json string from my object, but something weird is happening, one of entities losses data in the process, which is weird because when I'm debugging, the entity has values, but for some reason it…
Golan Kiviti
  • 3,895
  • 7
  • 38
  • 63
5
votes
2 answers

Using WCF DataContract in MVC SessionState using AppFabric cache

I have a Data Access Layer, a Service Layer, and a Presentation Layer. The Presentation Layer is ASP.NET MVC2 RTM (web), and the Service Layer is WCF (services). It's all .NET 3.5 SP1. The problem is that in the services, the objects being returned…
5
votes
4 answers

Can I prevent a specific datamember from being deserialized?

I have a datacontract like this [DataContract] class MyDC { [DataMember] public string DM1; [DataMember] public string DM2; [DataMember] public string DM3; } and sometimes I want to prevent DM2 from being deserialized…
floatingfrisbee
  • 928
  • 1
  • 10
  • 28
5
votes
2 answers

How to assign JsonProperty attribute to properties of classes inside DLL using Json.Net?

I have a class inside a DLL which is not labelled with DataContract, JsonProperty etc. Now I want to serialize instance of the class as JSON objects, with the C# property names shortened. For instance, the class is: public class Foo { public…
lzl124631x
  • 4,485
  • 2
  • 30
  • 49
5
votes
2 answers

Pass list of known types to object with its own XmlSerializer in (de-)serialization tree

I use C# 3 on microsoft .net 3.5 (VS2008). I have a problem with de-serialization. I use DataContract and DataMember in a hierarchy of classes that I want to be serializable. However, I also have polymorphism in one container, so I need to pass a…
v.oddou
  • 6,476
  • 3
  • 32
  • 63
5
votes
2 answers

WCF DataContract - marking member IsRequired=false

I have a contract as follows: [DataContract] public class MyObj { [DataMember(IsRequired=true)] public string StrA {get; private set;} [DataMember(IsRequired=false)] public string StrB {get; private set;} } What exactly does…
Tamim Sadikali
  • 203
  • 4
  • 11
5
votes
1 answer

WCF Data Contract - best/cleanest way to enforce required values?

I have a WCF data contract with a bunch of properties of primitive types like int and decimal, and DateTime (which is, of course, a struct). My co-worker suggested making them all nullable and then validating required values on the service end by…
lintmouse
  • 5,079
  • 8
  • 38
  • 54
5
votes
0 answers

DataContractSerializer serializes interface properties as System.Object / anyType

In an application I have the following interface / implementation structure: public interface IMyInterface { IMyOtherInterface InstanceOfMyOtherInterface { get; } } public interface IMyOtherInterface { string SomeValue { get;…
5
votes
3 answers

WCF Message & Data Contract, DTO, domain model, and shared assemblies

I have a web client that calls my WCF business service layer, which in turn, calls external WCF services to get the actual data. Initially, I thought I would use DTOs and have separate business entities in the different layers... but I'm finding…
Raymond
  • 3,382
  • 5
  • 43
  • 67
5
votes
3 answers

Should WCF DataContracts be value or reference types?

You're at the service's end of the wire and you don't know your clients. Why would you choose one over the other?
user134706
  • 1,010
  • 6
  • 9
4
votes
2 answers

WCF private member reference in DataContract class becomes NULL

I have a pecular problem in my WCF in the web services layer. When I instantiate a private member (_Wagon) of my class (This instantiation is not null) in WCF, after few seconds, it's become null. I've been trying to diagnose the problem, but no…
Clément
  • 43
  • 5
4
votes
2 answers

How do I tell DataContract to use the base class's GetEnumerator?

I have a generic class that implements Dictionary. I created a custom GetEnumerator that loops over the values instead of KeyValuePairs because I usually don't care about the keys. Here is a quick sample: public class AssetHolder :…
hypehuman
  • 1,290
  • 2
  • 18
  • 37
4
votes
2 answers

Can you make a DataContract with a Single ValueType based Value?

I am curious if it is possible to create a DataContract that will serialize like so: string value OR int What I am ultimately trying to do is return a basic type with a Custom element name.…
Devin
  • 61
  • 4