What's the point of a DataContract in WCF?

前端 未结 6 1634
情歌与酒
情歌与酒 2020-12-07 14:07

VS.net creates a template when you create a WCF project.

It adds a class to the iService1.cs file:

// Use a data contract as illustrated in the sampl         


        
6条回答
  •  情歌与酒
    2020-12-07 14:23

    I disagree with the poster who said "The DataContract is just a formal definition of a type that can be understood on both sides of the service boundary."

    The keyword here is "type". In .NET, a type is an object that can have fields, properties, and methods. However, when you decorate a class with DataContract in your WCF service, the result is not the class being magically transplanted into the calling code; not by a long shot! In the calling code, you will have a "proxy" class. The proxy class receives XML that represents the contents of the data contract. The calling code can receive these XML values through the proxy class, but it does not give the calling code access to the innards of the class decorate with datacontract.

提交回复
热议问题