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.
Questions tagged [datacontract]
798 questions
6
votes
1 answer
DataContract & DataMember attributes - how they affect type
what is the difference between class without DataContract attributes:
public class BankOperationResult
{
public int CurrentAmount { get; set; }
public bool Success { get; set; }
}
and the same class with DataContract…

dragonfly
- 17,407
- 30
- 110
- 219
6
votes
3 answers
WCF Service that returns a custom class generates errors in Reference.cs
I have a WCF Service project in Visual Studio 2008 that contains about 12 methods, some of which return primitive types like bool or string. I also have a Visual Studio Unit Test Project that references the published WCF Service. The Test Project…

Stuart Whiteford
- 521
- 7
- 22
6
votes
2 answers
Datacontract and dynamic return type WCF
I have a ServiceContract which returns dynamic type and looks like following:
public dynamic LoginViaOpenId(string openIdUrl)
The dynamic return type could be a DataContract that I have defined, or a string. But since I have not used my…

Amir
- 9,577
- 11
- 41
- 58
5
votes
1 answer
Data contracts: Ignore unknown types on deserialization
I have a plugin-based host application. Its settings are described as a data contract:
[DataContract(IsReference = true)]
public class HostSetup
{
[DataMember]
public ObservableCollection

Dennis
- 37,026
- 10
- 82
- 150
5
votes
4 answers
Null vs Value Not Set
We've written a web service which uses a simple entity translator to map the values of DTO back on to "real" server side business objects. As part of this excercise. We have come across an "interesting" distinction between explicitly set null values…

ChrisV
- 2,213
- 1
- 18
- 30
5
votes
2 answers
Is this the right way of implementing "Design by contract" pattern in PHP?
I've discovered the "Design by contract" pattern and how to implement in in PHP. I can't find a real world example of how to do this in PHP. First question is am i'm doing it in the right way? Second one is why the assert callback is not honored?
A…

gremo
- 47,186
- 75
- 257
- 421
5
votes
2 answers
JSON sample to [DataContract]
Is there any tool allowing to generate DataContract entity definitions based on a JSON sample? I'm really missing the old good WSDL metadata with code generation facilities.

Ivan G.
- 5,027
- 2
- 37
- 65
5
votes
1 answer
REST with Polymorphic DataContracts - Deserialization Fails
This has been driving me nuts all day, as I've made no changes yet I swear this was working the way I had intended yesterday.
I have a WCF 4 REST service defined with the following contract:
[ServiceContract]
public interface…

Paul Kirby
- 570
- 4
- 23
5
votes
3 answers
C# DataContractJsonSerializer fails when value can be an array or a single item
I use the DataContractJsonSerializer to parse a json string into a object hierarchie.
The json string looks like this:
{
"groups": [
{
"attributes": [
{
"sortOrder": "1",
…

Marco
- 543
- 3
- 9
- 21
5
votes
1 answer
Serialization / Derialization of a tree structure
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…

Eric Anastas
- 21,675
- 38
- 142
- 236
5
votes
1 answer
Custom DataMember names to deserialize a JSON class
I cannot manage to specify custom names for properties. I receive some JSON from the server (which I cannot change) with some ugly property names. I'd like the C# code to stick to naming conventions.
Below is the code I have (result0.StringValue…

Vincent Mimoun-Prat
- 28,208
- 16
- 81
- 124
5
votes
3 answers
Does adding [DataContract] and [DataMember] to all classes impact performance
Lets say we got a code generating tool that creates thousands of C# classes, and we sometimes need to add those attributes to them.
We are considering whether it is better to put [DataContract] and [DataMember] on all appropriate classes or we need…

Valentin Kuzub
- 11,703
- 7
- 56
- 93
5
votes
1 answer
DataContract for enums in WCF
I have a enum that I use via a WCF service in a .Net project. Now I want to add another enum, specified in the same way as the first.
But the second one does not get registered in Reference.cs, and therefore is not recognized from the project…

kakka47
- 3,479
- 8
- 44
- 52
5
votes
0 answers
(WCF) elementFormDefault="qualified" and attributeFormDefault="qualified" possible
Situation: I need to build a webservice based on an XSD.
It is possible to make an WCF webservice when the XSD says:
elementFormDefault="qualified" attributeFormDefault="qualified"
OR
elementFormDefault="unqualified"…

Aldwoni
- 1,168
- 10
- 24
5
votes
1 answer
Is there a xsd file for "http://schemas.microsoft.com/2003/10/Serialization/" namespace?
I want to create / infer schema for data-contract serialized classes.
When I use [DataContract(IsReference = true)] attribute the serializer is injecting attributes z:Id="i2" and z:Ref="i2" to reference the same object instances.
Both attributes…

stefando
- 495
- 1
- 7
- 13