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
7
votes
3 answers
WCF CollectionDataContract
I recently noticed in one of the articles the wcf service operation returned a collectiondatacontract
Users GetUsers(string someInput);
And Users type was defined as below:
[CollectionDataContract]
public class Users : List
{
…

stackoverflowuser
- 22,212
- 29
- 67
- 92
7
votes
2 answers
WCF datacontract vs class serialize
I understand that we can have more controls on a class if we use datacontract, however, consider the following 2 cases
[DataContract]
public class Customer
{
[DataMember]
public string CustomerName {get; set;}
[DataMember]
public…

Yuan
- 2,690
- 4
- 26
- 38
7
votes
3 answers
WCF Client having problems recognizing ServiceKnownTypes?
How would I tell the WCF service what KnownTypes to use when passing data back to the client?
I know I can use the [ServiceKnownType] attribute, which makes the service call run fine from a WCF Test Server, however it still fails from the client. Am…

Rachel
- 130,264
- 66
- 304
- 490
7
votes
3 answers
WCF DataMember attribute for read-only fields?
I am trying to create a class with a read-only Id field, however I am having problems retaining the value when the object passes through the WCF server.
I cannot set the [DataMember] attribute on the public property since there is no set method, and…

Rachel
- 130,264
- 66
- 304
- 490
7
votes
3 answers
Using custom DataContractResolver in WCF, to transport inheritance trees involving generics
I've got a WCF service, in which there are operations which accept a non-generic base class as parameter.
[DataContract]
class Foo
{ ... }
This base class is in turn inherited, by such generics classes as
[DataContract]
class Bar : Foo
{ ...…

Benson
- 71
- 1
- 2
7
votes
5 answers
Auto generating DataContract classes from Business Object Classes
I'm currently creating a .NET C# API. I have many classes, and some of them have to be transferred through a REST service as JSON. For example, I may have an account object with a lot of business meta-data:
public class Account
{
public…

automaton
- 1,972
- 5
- 25
- 40
7
votes
2 answers
WCF Client how can I deserialize an incompatible date format from the JSON response?
I have scoured the Net for info on this, but most of the results are about creating WCF services or situations where the service is under your control.
I am building a WCF client proxy for a RESTful JSON service which is out of my control. I am…

Jordan Morris
- 2,101
- 2
- 24
- 41
7
votes
1 answer
Is there any benifit in using DataContract and DataMember attributes while working with Asp.net Web API?
Many time i saw that developer are using DataContract and DataMember Attributes for their Asp.net Web API model?
What are the differences and best practices?

Cruiser KID
- 1,250
- 1
- 12
- 26
7
votes
3 answers
WCF, Entity Framework & Data Contracts
Using VS 2008 & .NET 3.5 SP1:
I am using WCF to allow clients to connect to a service that reads and writes database entries using Entity Framework. By default the entities that are generated automatically from the database have the DataContract…

Malcolm
- 400
- 1
- 2
- 11
6
votes
1 answer
WCF data contracts with base class and derived classes - what are the consequences of changes to the base class?
As I understand it you should use the Order property of the DataMember attribute so that you can add things to the data contract without the change in order causing things to break, but how should you approach this when you have base and sub…

Sam Holder
- 32,535
- 13
- 101
- 181
6
votes
1 answer
How to inherit from a class which is not marked with DataContractAttribute or SerializableAttribute in WCF?
In WCF, how to inherit from a class which is not marked with DataContractAttribute or SerializableAttribute and use that as datacontract ?
Ex: I have a custom class called "EmailAttachment" which I inherited from…

Shyju
- 214,206
- 104
- 411
- 497
6
votes
2 answers
Including XML Comments in DataContract Serializer Metadata
is there some way of sending the summary info of properties in a DataContract?
e.g.
[DataContract]
public class MyClass
{
///
/// My Summary information
///
[DataMember]
public int MyProperty {get;set;}
}
can this be…

Jose
- 10,891
- 19
- 67
- 89
6
votes
2 answers
.NET base type cannot be serialized by WCF
I'm writing a WCF service and want to expose some custom configuration elements (e.g. Custom ConfigurationSection and ConnectionStringSettings) so that I can modify the service's configuration.
One of my custom configuration elements inherits from…

vradenburg
- 163
- 1
- 4
- 9
6
votes
4 answers
Clone Whole Object Graph
While using this code to serialize an object:
public object Clone()
{
var serializer = new DataContractSerializer(GetType());
using (var ms = new System.IO.MemoryStream())
{
serializer.WriteObject(ms, this);
ms.Position =…

George Taskos
- 8,324
- 18
- 82
- 147
6
votes
1 answer
How do you replace the naming convention for ServiceContract and OperationContract?
I have the following code:
[ServiceContract(Name = "Save{0}")]
public ISave where T : BusinessObject
{
[OperationContract(Name = "Save")]
void Save(T obj);
}
public class SaveCustomer : ISave
{
public void Save(Customer…

michael
- 14,844
- 28
- 89
- 177