Adding methods to DataContract objects for WCF

后端 未结 4 1805
名媛妹妹
名媛妹妹 2020-12-06 08:20

Are DataContracts in WCF nothing more than DTOs? I was reading up about WCF and just had a couple of thoughts. It would be nice if some of the DataContract objects could hav

4条回答
  •  旧时难觅i
    2020-12-06 08:55

    Not sure if I correctly understood your answer, so correct me if I'm wrong.

    You can create a class library with your DataContracts classes and share the library between the client and server. In this way class marked [DataContract] will have methods (behavior) and [DataMember] fields/properties (state).

    When you will pass such objects between client and server via WCF state will be persisted, but since class library is shared you will have methods on both sides.

提交回复
热议问题