数据和序列化 [英] data and serialization

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

问题描述

大家好.. ^^;

我正在测试WCF(7月版),并且有几个问题...

1.为什么不能对DataTable进行序列化

我测试了数据集.可以通过MaxItemsInObjectGraph交付DataSet,但是,DataTable却不行.

有人说为什么要使用像DataTable这样的大对象……".只是使用自定义对象....但是,我怀疑为什么可以使用DataSet ... DataSet和DataTable,它们都可以继承ISerializable ...
DataSet可以序列化,但是DataTable不能序列化.... I无法理解为什么DataTable
无法序列化...

如果MS认为DataTable是巨大的对象,因此它的序列化是不正确的,为什么它们能够对DataSet进行序列化(因为与先前版本兼容?)

2.为什么我必须使用MaxItemsInObjectGraph?

我使用coustom对象,MaxItemsInObjectGraph = 2000000000 ...
我使用7列传输约60,000行..DataSet可以,但是不能传输自定义对象.
自定义对象只能传输8,000行. ..

太有趣了,很多人说DataSet是重对象,因此建议使用自定义对象
但是,DataSet包含大约60,000行可以传输,但是自定义对象不能...

我的测试代码在下面...我实际上不知道我的测试代码出了什么问题..
但是,测试结果是这样的.

如果MS认为与Web服务和远程处理(与以前的版本..like一样,如1.1点网框架)等以前的组件兼容,为什么不支持数据表,为什么必须
使用MaxItemsInObjectGraph ... ...

我认为数据表序列化和MaxItemsInObjectGraph的限制应该是可选的...
由于组件是以前的dotnet框架所致...

WCF端点-Web服务,com +组件等(已建立旧的点网框架版本..)

这样,我认为它在升级组件等(以前的点网框架版本..)方面更兼容.

我实际上不明白为什么wcf在这些方面有局限性....

请向我解释为什么和什么是WCF的数据标准....

--------测试代码

[ServiceContract]
公共接口IFactInternetSales
{
[FactInternetSale SelectFactInternetSales();
}}


[DataContract]
公共类FactInternetSale
{
私有字符串_ErrMsg;
public List< FactInternetSalesDT> _FactInternetSalesDT =新列表< FactInternetSalesDT>();

[DataMember]
public List< FactInternetSalesDT> LFactInternetSales
{
get
get {br} {
返回return _FactInternetSalesDT; }

[DataMember]
公共字符串ErrMsg
{{br> get {return _ErrMsg; }
设置{_ErrMsg =值; }

.
}

[DataContract]
公共类FactInternetSalesDT
{ ;
专用小数_UnitPrice;
专用小数_ExtendedAmount;

[DataMember]
public int ProductKey
{
}
设置{_ProductKey = value; }
}
[DataMember]
公用字符串EnglishProductName
{{<>> get {return _EnglishProductName; }
设置{_EnglishProductName = value; }
}
[DataMember]
公用字符串FullDate
{{<>> get {return _FullDate; }
设置{_FullDate =值; }
}
[DataMember]
公共字符串SalesOrderNumber
{{
} get {return _SalesOrderNumber; }
设置{_SalesOrderNumber =值; }
}
[DataMember]
public int RevisionNumber
{
get {return _RevisionNumber; }
设置{_RevisionNumber =值; }
}
[DataMember]
公共十进制UnitPrice
{{ }
设置{_UnitPrice =值; }
}
[DataMember]
公用十进制ExtendedAmount
{{ }
设置{_ExtendedAmount =值; }
}}
}

公共类FactInternetSalesFacade:IFactInternetSales

public FactInternetSale SelectFactInternetSales()
{
FactInternetSale _FactInternetSale = null;

DataTable dt = new DataTable();

尝试结果,{结果,DT = biz.SelectFactInternetSales();结果,如果(dt.Rows.Count&0)结果,{结果_FactInternetSale =新FactInternetSale();

#region데이터가

foreach(DataRow dt.Rows中的行)

如果(卓尔["&的ProductKey QUOT;]!= DBNull.Value)结果,{结果tdt.ProductKey = int.Parse(卓尔["&的ProductKey QUOT].的ToString());结果,}如果点击(卓尔[" EnglishProductName"]!= DBNull.Value)结果,{结果tdt.EnglishProductName =卓尔[" EnglishProductName"].的ToString();结果,}结果,如果(卓尔[" FullDate"]!= DBNull.Value)结果,{结果tdt.FullDate =卓尔[" FullDate"].的ToString();结果,}结果,如果(卓尔[" SalesOrderNumber" ;!] = DBNull.Value)结果,{结果tdt.SalesOrderNumber =卓尔[" SalesOrderNumber"]的ToString();结果,}结果,如果(卓尔[" RevisionNumber& QUOT] = DBNull.Value)结果,{结果tdt.RevisionNumber = int.Parse(卓尔[" RevisionNumber"]的ToString());结果,}!结果,如果(卓尔["单价"] = DBNull.Value)结果,{结果tdt.UnitPrice = decimal.Parse(卓尔["单价"]的ToString());结果,}!结果,如果(卓尔[" ExtendedAmount]!= DBNull.Value)
{{
t tdt.ExtendedAmount =十进制.

_FactInternetSale._FactInternetSalesDT.Add(tdt);

#endregion结果,},点击}结果,捕捉(异常前),点击{结果_FactInternetSale.ErrMsg = ex.Message;结果,}结果,最后结果,{
biz = null;
dt = null;
}

返回_FactInternetSale;
}
}

解决方案

可以标记为无效.

blockquote>

Hi~ everyone..^^;

I am testing about WCF(with July version) and have a couple of questions...

1. why can not be serialization about DataTable

I tested DataSet. It is possilble to deliver DataSet with MaxItemsInObjectGraph
However, DataTable dose not...

some people says "Why use huge object like DataTable..." just use custom object....
but, I doubt Why can use DataSet...DataSet and DataTable, both inherit ISerializable...
DataSet can be serialize but DataTable can not be serialize....I can not understand why DataTable
can not be serialize...

if MS think DataTable is huge object and so it's Serialization is not right, Why they make it possible to be able to serialize DataSet( because compatible with previous version??)

2. Why I have to use MaxItemsInObjectGraph ?

I use coustom object and MaxItemsInObjectGraph = 2000000000 ...
I transfer about 60,000 rows with 7 Columns..DataSet is Ok, but can not transfer custom object.
custom object just can transfer 8,000 rows....

that is so funny, many people says DataSet is heavy object so recommand to use custom object
but, DataSet include about 60,000 rows can be transfered but custom object can not...

my test code is below...I actually don't know my test code is what is wrong..
but, test result is like that..

if MS think to be compatible with previous components like web services and remoting(made with previous version ..like 1.1 dot net framework)...why dose not support datatable and why have to
use MaxItemsInObjectGraph ......

I think limitation of datatable serialization and MaxItemsInObjectGraph should be optional...
because of components made previous dotnet framework...

 WCF endpoint - Webservice, com+ components etc (made previous dot net framework version..)

like this, I think it is more compatible in upgradeing components etc (made previous dot net framework version..) ...

I actually don't understand why wcf has limitation about those....

please, explain the resion to me why and what actually is WCF's standard for Data....

--------test code

           [ServiceContract]
    public interface IFactInternetSales
    {
        [OperationContract]
        FactInternetSale SelectFactInternetSales();
    }


    [DataContract]
    public class FactInternetSale
    {
        private string _ErrMsg;
        public List<FactInternetSalesDT> _FactInternetSalesDT = new List<FactInternetSalesDT>();

        [DataMember]
        public List<FactInternetSalesDT> LFactInternetSales
        {
            get
            {
                return _FactInternetSalesDT;
            }
            set { _FactInternetSalesDT = value; }
        }

        [DataMember]
        public string ErrMsg
        {
            get { return _ErrMsg; }
            set { _ErrMsg = value; }
        }

       
    }

    [DataContract]
    public class FactInternetSalesDT
    {
        private int     _ProductKey;
        private string  _EnglishProductName;
        private string  _FullDate;
        private string  _SalesOrderNumber;
        private int     _RevisionNumber;
        private decimal _UnitPrice;
        private decimal _ExtendedAmount;

        [DataMember]
        public int ProductKey
        {
            get { return _ProductKey; }
            set { _ProductKey = value; }
        }
        [DataMember]
        public string EnglishProductName
        {
            get { return _EnglishProductName; }
            set { _EnglishProductName = value; }
        }
        [DataMember]
        public string FullDate
        {
            get { return _FullDate; }
            set { _FullDate = value; }
        }
        [DataMember]
        public string SalesOrderNumber
        {
            get { return _SalesOrderNumber; }
            set { _SalesOrderNumber = value; }
        }
        [DataMember]
        public int RevisionNumber
        {
            get { return _RevisionNumber; }
            set { _RevisionNumber = value; }
        }
        [DataMember]
        public decimal UnitPrice
        {
            get { return _UnitPrice; }
            set { _UnitPrice = value; }
        }
        [DataMember]
        public decimal ExtendedAmount
        {
            get { return _ExtendedAmount; }
            set { _ExtendedAmount = value; }
        }
    }

 

 

 public class FactInternetSalesFacade : IFactInternetSales
    {

        public FactInternetSale SelectFactInternetSales()
        {
            FactInternetSale _FactInternetSale = null;
           
            FactInternetSalesNTx biz = new FactInternetSalesNTx();

            DataTable dt = new DataTable();

            try
            {
                dt = biz.SelectFactInternetSales();
                if (dt.Rows.Count > 0)
                {
                    _FactInternetSale = new FactInternetSale();

                    #region 데이터 추가

                    foreach (DataRow drow in dt.Rows)
                    {
                        FactInternetSalesDT tdt = new FactInternetSalesDT();

                        if (drow["ProductKey"] != DBNull.Value)
                        {
                            tdt.ProductKey = int.Parse(drow["ProductKey"].ToString());
                        }
                        if (drow["EnglishProductName"] != DBNull.Value)
                        {
                            tdt.EnglishProductName = drow["EnglishProductName"].ToString();
                        }
                        if (drow["FullDate"] != DBNull.Value)
                        {
                            tdt.FullDate = drow["FullDate"].ToString();
                        }
                        if (drow["SalesOrderNumber"] != DBNull.Value)
                        {
                            tdt.SalesOrderNumber = drow["SalesOrderNumber"].ToString();
                        }
                        if (drow["RevisionNumber"] != DBNull.Value)
                        {
                            tdt.RevisionNumber = int.Parse(drow["RevisionNumber"].ToString());
                        }
                        if (drow["UnitPrice"] != DBNull.Value)
                        {
                            tdt.UnitPrice = decimal.Parse(drow["UnitPrice"].ToString());
                        }
                        if (drow["ExtendedAmount"] != DBNull.Value)
                        {
                            tdt.ExtendedAmount = decimal.Parse(drow["ExtendedAmount"].ToString());
                        }

                        _FactInternetSale._FactInternetSalesDT.Add(tdt);
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                _FactInternetSale.ErrMsg = ex.Message;
            }
            finally
            {
                biz = null;
                dt = null;
            }

 

            return _FactInternetSale;
        }
    }

解决方案

Can be marked as dead.


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

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