What's the point of a DataContract in WCF?

前端 未结 6 1633
情歌与酒
情歌与酒 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:22

    The DataContract is just a formal definition of a type that can be understood on both sides of the service boundary.

    If you return, as in your example, a "MyUserCollection" object, the consumers of your service will need to reference the innards of your service/system, which is a violation of the SOA tenet of explicit boundaries. By using a DataContract, you are publishing the structure of your return types in a loosely-coupled way.

提交回复
热议问题