开发者

DataContract attribute -WCF

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

I c开发者_如何学Goan'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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜