user274364
user274364

Reputation: 1857

DataContract attribute -WCF

Is DataContract attribute is deprecated in ASP.NET 4.0 WCF ? I can see only DataContractFormat attribute.

I can't apply DataContractFormat attribute over struct.

example

[DataContractFormat]
public struct Contact
{
  public string firstName;
  public string lastName;
}

It throws an error saying that DataContractFormat artribute can only be used on class, interface and methods.

Upvotes: 2

Views: 7711

Answers (3)

TomTom
TomTom

Reputation: 62093

DataContract is not deprecated - where the heck did you get that idea from?

DataCOntractFORMAT is something totally different. I suggest you please read the documentation ;) Helps a lot. Will also explain what DataContractFormat is for.

http://msdn.microsoft.com/en-us/library/system.servicemodel.datacontractformatattribute.aspx

As you can see in the example this attribute goes on the class/interface that defines the SERVICE CONTRACT. It controls how for that service data serializaton is (guess what) formatted.

Upvotes: 3

Tal Fisher
Tal Fisher

Reputation: 71

You have to add a reference to the System.Runtime.Serialization assembly (right click References, add ref...)

Upvotes: 7

marc_s
marc_s

Reputation: 754220

No, the .NET 4 still contains the DataContractAttribute:

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute%28v=VS.100%29.aspx

and it should be able to be applied to class or struct.

Upvotes: 7

Related Questions