开发者

Pass DataSet From WCF Service to Silverlight application

I have a DataSet of around 20,000 rows that I convert into an IEnumerable<Dictionary<string, object>> with this code:

IEnumerable<Dictionary<string, object>> IEnu = ds.Tables[0]
    .AsEnumerable()
    .Select(r => ds.Tables[0]
        .Columns.Cast<DataColumn>().Select(c => new {
            Column = c.ColumnName,
            Value = r[c]
        }).ToDictionary(
            i => i.Column,
            i => i.Value != DBNull.Value ? i.Value : null
        )
    );

but the IENU object size is much too large (around 开发者_JS百科7 to 8 MB). This is a very large size to pass thru the service. Another option is to generate XML of dataset (it's around 1 to 2 MB) but there is still a problem in that I don't recognize a datatype of XML node data, also I don't create any class which contain's property of XML node and create a list because my select query is criteria base so generate at client side after pass in sql

So how can I pass datatype in XML or is there any other way to pass data from WCF service to a Silverlight application?


Services should return strongly typed objects that are serialized to an object or an array of objects into either SOAP, POX (plain old xml rest) or json (javascript object notation). If you use REST, WCF can return XML or JSON format simply by attributing objects with DataContract attributes.

DataSets (or DataReaders) come back from databases. Services provide an abstraction over the storage mechanism which may change over time.

By passing back serialized objects, the silverlight (or anyother client) can deserialize them into objects which are much easier to deal with.

Also, I second the comment about not passing back 20K rows. Find ways to page your data (request in chunks).

Search for REST and WCF or Web Services and WCF.

Hope that helps.


This might be an interesting post for you http://weblogs.asp.net/sweinstein/archive/2009/01/03/creating-high-performance-wcf-services.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜