[下载]DataSet Remoting(DataSetSurrogate)
[下载]DataSet Remoting(DataSetSurrogate)
CSharp DataSetSurrogate Usage Sample ==================================== TestSurrogate is the client application. It calls DSServer, which is the server component. Both TestSurrogate and DSServer import DataSetSurrogate class, this is the class that performs the So that both the client and server use same instance of the DataSetSurrogate class, I setup All projects are build using Visual Studio .NET 2003. Build the projects in the following order: 1. Build DataSetSurrogate project. C:\SurrogateSample\CSharp>gacutil /if .\DataSetSurrogate\bin\Release\DataSetSurrogate.dll Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573 Assembly successfully added to the cache 4. Build DSServer project. C:\SurrogateSample\CSharp>gacutil /if .\DSServer\bin\Release\DSServer.dll Microsoft (R) .NET Global Assembly Cache Utility. Version 1.1.4322.573 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 Installed Assembly:
8. Build TestSurrogate project last, as it references both DSServer and DataSetSurrogate classes. DataSet Remoting Authors: File: DataSetRemoting.doc Keywords: WEBDATA, MANAGED, PROVIDER 1. IntroductionThe .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. DescriptionDataSet 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 DataSetWe 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.
/** 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 classDataSetSurrogate 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 MembersThe 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 ForeignKeyConstraintsForeign 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 RelationsDataSet 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 ExtendedPropertiesThis is a simple HashTable that contains the ExtendedProperty name as the key and its corresponding value is the property’s value. 3.1.5 DataTableSurrogatesSimilar 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 DataColumnSurrogateDataColumnSurrogate 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 MembersAll 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 DataTableSurrogateDataTableSurrogate 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 MembersThe 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 UniqueConstraintsUniqueConstraint 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 RowStatesA 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 RecordsRecords 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 RowErrorsRowErrors 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 ColumnErrorsThis 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 DataColumnSurrogatesJust 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 SequenceIt 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 DataSetRemoting 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#实现.Net Remoting服务端与客户端通信 [原创] 使用Tcp/Ip下载文件(图) C#.Net组件开发(高级篇) - 全部源码下载 ExRichTextEdit 控件下载 DOC2CHM V3.4/2.5下载 C#.NET C/S结构版本自动升级解决方案开发文档下载 DevExpress 9.26 运行时汉化中文简体汉化包下载 模块主窗体的流程控制按钮图标设计PSD文件下载 国内省市区数据库.xls 下载 TeeChart V5.0 图形组件 演示视频下载 生成流水号,数字序号可以指定长度,SP下载 Winform ERP系统 漂亮图标下载网站 审核/反审核jpg png PSD文件下载 C#.NET MVC WebApi后台开发框架入门完整版下载 图片资源上传下载WebApi服务器
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 | |