简体   繁体   中英

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.

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.

您必须添加对System.Runtime.Serialization程序集的引用(右键单击引用,添加引用...)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM