WCF datacontract vs类序列化 [英] WCF datacontract vs class serialize

查看:79
本文介绍了WCF datacontract vs类序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解如果使用datacontract,我们可以在一个类上拥有更多控件,但是,请考虑以下两种情况

I understand that we can have more controls on a class if we use datacontract, however, consider the following 2 cases

[DataContract]
public class Customer
{
    [DataMember]
    public string CustomerName {get; set;}

    [DataMember]
    public int Age{get; set;}
}

public class Customer
{
    public string CustomerName {get; set;}
    public int Age{get; set;}
}

它们都在.net客户端上正确序列化.我个人不使用第二个例子.有人可以指出两类的区别吗?我打算在两个类中都发送所有公共属性.

They both get serialized correctly on .net client. And personally I do not use second example. Can anybody point me the differences in the 2 classes? I meant to send all public properties in both classes.

推荐答案

第二个版本是数据合同的POCO(普通旧CLR对象)版本,自3.5 sp1起可以与WCF一起使用.

The second version is the POCO (plain old CLR object) version of your data contract and can be used with WCF since 3.5 sp1.

我不建议您使用它,因为它对序列化(命名空间属性...)的控制很少,并且将您的服务实体与业务实体(与POCO相同)相结合

I would not recommend using it though as it gives you very little control on the serialization (namespace attributes...) and it couples your service entities with your business entities (which can be same with POCO)

这篇关于WCF datacontract vs类序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆