[下载]DataSet Remoting(DataSetSurrogate)


[下载]DataSet Remoting(DataSetSurrogate)


将DATASET、DATATABLE序列化

使用说明:


CSharp DataSetSurrogate Usage Sample
====================================

TestSurrogate is the client application.  It calls DSServer, which is the server component. 
I designed DSServer to be hosted in COM+, but it can be remotely hosted in any manner desired.

Both TestSurrogate and DSServer import DataSetSurrogate class, this is the class that performs the
serialization of the DataSet.

So that both the client and server use same instance of the DataSetSurrogate class, I setup
the class to have a strong name using a key file (DataSetSurrogate.snk) and it needs to be added to the GAC.

All projects are build using Visual Studio .NET 2003.

Build the projects in the following order:

1. Build DataSetSurrogate project.
2. Open up the Visual Studio .NET 2003 Command prompt and CD to C:\SurrogateSample\CSharp folder.
3. Run gacutil to add DataSetSurrogate to the GAC, like so:

 C:\SurrogateSample\CSharp>gacutil /if .\DataSetSurrogate\bin\Release\DataSetSurrogate.dll

 Microsoft (R) .NET Global Assembly Cache Utility.  Version 1.1.4322.573
 Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

 Assembly successfully added to the cache

4. Build DSServer project.
5. Run gacutil to add DSServer to the GAC:

 C:\SurrogateSample\CSharp>gacutil /if .\DSServer\bin\Release\DSServer.dll

 Microsoft (R) .NET Global Assembly Cache Utility.  Version 1.1.4322.573
 Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

 Assembly successfully added to the cache

6. Run regsvcs on DSServer to add the component to COM+:

 C:\SurrogateSample\CSharp>regsvcs .\DSServer\bin\Release\DSServer.dll
 Microsoft (R) .NET Framework Services Installation Utility Version 1.1.4322.573
 Copyright (C) Microsoft Corporation 1998-2002.  All rights reserved.

 Installed Assembly:
         Assembly: C:\SurrogateSample\CSharp\DSServer\bin\Release\DSServer.dll
         Application: DSServer_CS
         TypeLib: C:\SurrogateSample\CSharp\DSServer\bin\Release\DSServer.tlb


7. If you are testing on a Windows 2003 machine, open Component Services
   snap-in (Administrative Tools) and the open property sheet for DSServer_VB
   application.  Select the Identity tab and choose Local Service for the account.

8. Build TestSurrogate project last, as it references both DSServer and DataSetSurrogate classes.


DataSet Remoting

Authors:        Kawarjit Bedi

                   Ravinder Vuppula

File:              DataSetRemoting.doc
Status:         Draft
Last Change:  9/15/2003 11:28:00 PM
Printed:         9/10/2003 12:55 PM

Keywords:     WEBDATA, MANAGED, PROVIDER

 

1.     Introduction

 

The .Net framework provides Remoting mechanisms for sending/receiving objects across appdomains, processes or machines. DataSet instances can be accessed via Remoting. Generally, Remoting is more efficient than WebServices. But for large DataSets, that is not the case. Accessing large DataSets over WebServices has better performance characteristic than remoting. The memory consumed by the system during remoting increases rapidly with the dataset size, it may not scale well for large datasets. This document describes a solution that can be used to optimize DataSet remoting. It improves both memory consumption and end to end latency.

2.     Description

DataSet serializes its content as XML for the purposes of remoting. This works well for small DataSet (cumulative count of rows in all tables is less than 10000 rows). However, this does not scale well for large DataSet, and results in increased memory usage and slow performance. To improve DataSet remoting performance, DataSet contents can be copied to a surrogate class that is structured such that it can be easily and efficiently remoted. This gives good performance for small as well as large DataSet.

3.     Remoting DataSet

We first describe how to remote an untyped DataSet and subsequently in the next section we will describe how to remote a typed DataSet.

 

Remoting a DataSet using a custom class involves doing the following:

1. Create a surrogate class for

- DataSet

     - DataTable

     - DataColumn.

2. All surrogate classes are marked as [Serializable], so it does not have to implement ISerializable for custom remoting.

3. The surrogate class is primarily designed for remoting and it is structured accordingly. All its members are serializable, i.e. their types are either the built-in types or belong to a serializable class.

4. The surrogate class will provide

- A constructor that accepts as input the object that is being surrogated - in this case the object being surrogated is DataSet.

- A method that constructs back the object that is being surrogated [DataSet in this case] from the surrogate object.


The client and server code would look like the following:

/**

Server code

**/

public DataSetSurrogate GetDataSetSurrogate() {

    DataSet ds = new DataSet();

    ds.ReadXmlSchema(“Northwind.xsd”);

    ds.ReadXml(“Northwind.xml”);

    return new DataSetSurrogate(ds);

}

 

/**

Client code

**/

DataSetSurrogate dss = GetDataSetSurrogate();

DataSet ds = dss.ConvertToDataSet();

 

 

3.1     DataSetSurrogate class

DataSetSurrogate class is designed to be a surrogate for the DataSet class. It has a constructor that accepts DataSet as an argument and initializes itself with the content of the passed DataSet. It provides ConvertToDataSet() method that returns an equivalent DataSet instance.

 

The portion of the class definition that defines its members is given below:

 

[Serializable]

public class DataSetSurrogate : ISerializationSurrogate {

    private string      _datasetName;

    private string      _namespace;

    private string      _prefix;       

    private bool        _caseSensitive;

    private CultureInfo _locale;

    private bool        _enforceConstraints;   

    private ArrayList   _fkConstraints; of foreign key constraints   

    private ArrayList   _relations;   

    private Hashtable   _extendedProperties;

    private DataTableSurrogate[] _dataTableSurrogates;

}   

3.1.1     Class Members

The DataSetSurrogate class members are either a collection of some kind or are simple built-on types. In this section we describe the members whose type is a kind of a collection (i.e. ArrayList, HashTable or Array)

3.1.2     ForeignKeyConstraints

Foreign Key constraint contains information about the child table, child columns, parent table and the associated primary/unique key. Unlike other constrains that are confined to a single table (i.e. Unique constraint) this constraint is across tables. The ForeignKeyConstraint collection gets serialized as part of DataSetSurrogate, while all other constraints get serialized as part of DataTableSurrogate.

 

Format of each item in the list

String ConstraintName

ArrayList parentInfo {ParentTableIndex, ParentColumnOrdinal(s)}

ArrayList childInfo {ChildTableIndex, ChildColumnOrdinal(s)}

Boolean AcceptRejectRule, UpdateRule, DeleteRule

HashTable ExtendedProperties

 

Where: the words in italics indicate the type of the corresponding value. The list only contains the value, their corresponding type is known to the code that encodes/decodes the ForeignKeyConstraint object.

3.1.3     Relations

DataSet supports creating of DataRelation on DataTables. The DataRelation associates two tables in a parent - child relationship.

 

Format of each item in the list

String RelationName

ArrayList parentInfo {parentTableIndex, primaryKeyOrdinal(s)}

ArrayList childInfo {ChildTableIndex, ForeignKeyOrdinals}

Boolean IsNested

HashTable ExtendedProperties

 

Where: the words in italics indicate the type of the corresponding value. The list only contains the value, their corresponding type is known to the code that encodes/decodes the DataRelation object.

3.1.4     ExtendedProperties

This is a simple HashTable that contains the ExtendedProperty name as the key and its corresponding value is the property’s value.

3.1.5     DataTableSurrogates

Similar to a DataSet that contains a collection of DataTable, DataSetSurrogate contains an array of DataTableSurrogate object(s). DataTableSurrogate is marked serializable and its remoting is automatically taken care of by.NET platform.

3.2     DataColumnSurrogate

DataColumnSurrogate class is designed to be a surrogate for the DataColumn Class. It has a constructor that takes a DataColumn as an argument and initializes itself with the content of the passed DataColumn. DataColumnSurrogate provides ConvertToDataColumn() method that returns an equivalent DataColumn instance.

 

The class’s members are given below:

 

[Serializable]

public class DataColumnSurrogate {

    private string      _columnName;

    private string      _namespace;

    private string      _prefix;            

    private MappingType _columnMapping;

    private bool        _allowNull;

    private bool        _autoIncrement;

    private long        _autoIncrementStep;

    private long        _autoIncrementSeed;

    private string      _caption;

    private object      _defaultValue;

    private bool        _readOnly;

    private int         _maxLength;

    private Type        _dataType;

    private string      _expression; 

    private Hashtable   _extendedProperties;

}

3.2.1     Class Members

All DataColumnSurrogate class members are of simple built-in types. The composition of the ExtendedProperties HashTable is similar to the construction of DataSetSurrogate’s ExtendedProperties.

3.3     DataTableSurrogate

DataTableSurrogate class is designed to be a surrogate for the DataTable class. It’s designed like the other surrogate classes. It has (1) a constructor that accepts the base object, in this case a DataTable and (2) its ConvertToDataTable() method can be used to construct an equivalent DataTable object.

 

The DataTableSurrogate class with only its class members is listed below.

 

[Serializable]

public class DataTableSurrogate {

    //DataTable properties

    private string      _tableName;

    private string      _namespace;

    private string      _prefix;

    private bool        _caseSensitive;

    private CultureInfo _locale;

    private string      _displayExpression;

    private int         _minimumCapacity;     

    private ArrayList   _uniqueConstraints;       

    private Hashtable   _extendedProperties;

    private DataColumnSurrogate[] _dataColumnSurrogates;             

    private BitArray    _rowStates;

    private object[][]  _records; 

    private Hashtable   _rowErrors;

    private Hashtable   _columnsInError;

}

 

3.3.1     Class Members

The DataTableSurrogate class members are either a collection of some kind or are simple built-in types. In this section we describe the members whose type is a kind of collection (i.e. ArrayList, HashTable or Array)

3.3.1.1     UniqueConstraints

UniqueConstraint contain information about the current table and its unique key columns.

 

Format of each item in the list

String ConstraintName

ArrayList colInfo {ColumnOrdinal(s)}

Boolean IsPrimaryKey

HashTable ExtendedProperties

 

Where: the words in italics indicate the type of the encoded value.

3.3.1.2     RowStates

A DataTable contains zero or more DataRows in its DataRowCollection. For the purpose of remoting performance, the DataRow’s content is stored in the following DataTableSurrogate members

-         RowStates

-         Records

-         RowErrors

-         ColumnErrors

For optimizing remoting performance, the row content is not send as a collection of row values but as a collection of column values. RowStates is used to keep track of row’s state and its associated current and original record values. To optimize memory utilization, RowStates is a BitArray instead of an array of integers. A set of 2 bits is used to represent a single row’s state. The RowStates use the following encoding: [00]->Unchanged, [01]->Added, [10]->Modified, [11]->Deleted.

3.3.1.3     Records

Records are sent in a 2 dimensional array that contains a list of column values. As a row can have up to 2 records [original, current], the size of each column values array is twice the number of rows. Based on the row state, it knows the records associated with each row. The organization of the records is what gives DataSetSurrogate object the most performance boost during remoting.

3.3.1.4     RowErrors

RowErrors is a HashTable that contains rows that have errors. The key is the row index and the value is the row’s error message.

3.3.1.5     ColumnErrors

This is a HashTable that contains the column specific errors for the rows that has errors. The key is the row index and the value is an ArrayList with 2 items, each of which is an ArrayList. The first item identifies the column ordinals that have errors, and the second item contains the error message for the corresponding column in error.

3.3.1.6     DataColumnSurrogates

Just as DataTable contains a collection of DataColumn, DataTableSurrogate contains an array of DataColumnSurrogate objects. This is used to contain the column information for the current Table. Please see section 3.2 for more information on DataColumnSurrogate class

3.3.2     Deserialization Sequence

It is important to observe the sequence during the deserialization process. Setting of expressions on the expression columns should be delayed until the relations have been processed, otherwise setting the expression on the columns would throw exception.

 

4.     Remoting Typed DataSet

Remoting of a typed dataset is very similar to remoting a standard dataset. The DataSetSurrogate object does not know about TypedDataSet but since, the content of both types of DataSet is the same the standard dataset retrieved from the DataSetSurrogate can be used to populate a typed dataset instance.

 

The following example illustrates how to construct a typical TypedDataSet instance from its corresponding DataSet instance.

     

/**

Server code

**/

 

public DataSetSurrogate GetDataSetSurrogate() {

    Northwind nwds = new Northwind();

    nwds.ReadXml(“Northwind.xml”);

    return new DataSetSurrogate(nwds);

}

 

/**

Client code

**/

 

DataSetSurrogate dss = GetDataSetSurrogate();

Northwind nwds = new Northwind();

dss.ReadDataIntoDataSet(nwds);

 




本文来源:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:C#.NET 会计系统开发框架模板(C/S Winform架构) 巨献!
下一篇:C#.Net用户自定义控件制作教程
评论列表

发表评论

评论内容
昵称:
关联文章

[下载]DataSet Remoting(DataSetSurrogate)
C# DataSet和DataTable
C#DataSet监视工具2.0(DataSet Watch 2.0)
.NET构架下Remoting和WebService技术区别
DataTable已属于另一个DataSet
C#实现.Net Remoting服务端与客户端通信
支持ADO.NET方法 返回DataTable/DataSet
调用WebApi接口POST操作失败Unable to connect to the remote server
tb_DataSet表(账套数据库配置表)详解
系统库tb_DataSet表RemoteServerIP与LocalServerIP有何区别
开发框架多账套连接表tb_Dataset以及分配用户的账套权限
加密解密tb_DataSet/tb_MyUser表的密码|C/S框架网
CS系统框架 - 负载均衡(Load Balancing)源码下载
C#,Asp.Net多线程断点续传下载
C#.Net WCF实例详解及源码下载
ClassGenerator(ORM生成器)下载
ExRichTextEdit 控件下载
学习C#.NET基础知识(学习重点请下载附件)
下载纸箱行业ERP系统
ERP标准流程DOC文档下载

热门标签
.NET5 .NET6 .NET7 APP Auth-软件授权注册系统 Axios B/S B/S开发框架 Bug Bug记录 C#加密解密 C#源码 C/S CHATGPT CMS系统 CodeGenerator CSFramework.DB CSFramework.EF CSFrameworkV1学习版 CSFrameworkV2标准版 CSFrameworkV3高级版 CSFrameworkV4企业版 CSFrameworkV5旗舰版 CSFrameworkV6.0 DAL数据访问层 Database datalock DbFramework Demo教学 Demo下载 DevExpress教程 DOM EF框架 Element-UI EntityFramework ERP ES6 Excel FastReport GIT HR IDatabase IIS JavaScript LINQ MES MiniFramework MIS NavBarControl Node.JS NPM OMS ORM PaaS POS Promise API Redis SAP SEO SQL SQLConnector TMS系统 Token令牌 VS2022 VSCode VUE WCF WebApi WebApi NETCore WebApi框架 WEB开发框架 Windows服务 Winform 开发框架 Winform 开发平台 WinFramework Workflow工作流 Workflow流程引擎 版本区别 报表 踩坑日记 操作手册 代码生成器 迭代开发记录 基础资料窗体 架构设计 角色权限 开发sce 开发技巧 开发教程 开发框架 开发平台 开发指南 客户案例 快速搭站系统 快速开发平台 秘钥 密钥 权限设计 软件报价 软件测试报告 软件简介 软件开发框架 软件开发平台 软件开发文档 软件体系架构 软件下载 软著证书 三层架构 设计模式 生成代码 实用小技巧 收钱音箱 数据锁 数据同步 微信小程序 未解决问题 文档下载 喜鹊ERP 喜鹊软件 系统对接 详细设计说明书 行政区域数据库 需求分析 疑难杂症 蝇量级框架 蝇量框架 用户管理 用户开发手册 用户控件 在线支付 纸箱ERP 智能语音收款机 自定义窗体 自定义组件 自动升级程序