views:

410

answers:

2

Hello everyone,

I am designing a WCF interface which returns status of all orders (Order data structure includes two members, a string type ID and an enum orderstatus, and designed as DataContract), the total # of orders are very large, about 10M. I am concerning about the traffic and impact to server side if client calls this interface API to get all order status and frqeuently call this API.

Any advice?

I am using VSTS 2008 + C# + .Net 3.5 + WCF.

thanks in advance, George

+2  A: 
  • Dont return all 10m record.
  • Use Paging Technology...
ozczecho
1. If I do not return 10M record, how could client knows the exact status of all orders? Any more advice?2. Use Paing technologies -- I only know paging from ASP.Net, and not know how to use it in WCF, any advice?
George2
+2  A: 

I would support ozczecho - why would you ever want to return 10M records? Will your customers REALLY want to sift through 10M orders?? I highly doubt it....

Limit the number - by e.g. date ranges (all orders from 1Q/09), or by any other criteria. Just because you could return 10M rows doesn't mean it'll really be a good idea.

Also, together with SQL Server, you could easily implement paging, e.g. you could have your WCF service send back the first e.g. 100 rows, and send back a flag indicating there's more, and then have your client request rows 101 through 200 etc. It takes a bit of logic, but it would make communication just THAT much easier (and quicker)!

Also, in WCF, you have to define maximum message sizes - they're normally at 64K. The reason for this is the fact that a message needs to be assembled in memory, in full, before being able to be transmitted. Imagine you have 50 clients hitting your server - how much memory can you really set aside for "message assembly" on your server?

Marc

UPDATE:
One way you can achieve paging in a service would be by having a call something like this:

[OperationContract]
public List<Orders> GetOrders(string searchCriteria, string sortExpression, 
                              int skipFirstRows, int takeRows)

This is inspired by the .Skip() and .Take() extension methods introduced by LINQ.

In this case, you could call GetOrders and define some search criteria (that might be a class, too, instead of just a string) to match your orders, you can define how to sort the orders by specifying sortExpression, and then you tell the service that you want to skip the first n rows and then take x rows.

So a call

List<Orders> result = GetOrders(criteria, sort, 0, 50)

would fetch the first 50 rows. Once you're done, you can call again:

List<Orders> result = GetOrders(criteria, sort, 50, 50)

and now you'd skip the first 50 rows (which you've already displayed / reported on) and then you take the next 50 (rows 51-100).

Of course, if your WCF service on the backend uses LINQ, you can translate that directly into calls to .Skip() and .Take() on your LINQ queries! :-)

UPDATE 2:
Are you working against SQL Server 2005 or higher? Check out the Common Table Expressions (CTE) which are basically the basis for what LINQ does. This allows you to define "virtual" view on your data and select only a certain section of the data set.

See more information here:

marc_s
1. "you could have your WCF service send back the first e.g. 100 rows, and send back a flag indicating there's more, and then have your client request rows 101 through 200 etc" -- intereted to implement this idea. But since new to this idea, not sure how to define interface, could you share some interface declaration code please? 2. "define maximum message sizes" -- I think only request message size could be defined? Could we define maximum response message size? 3. "ozczecho" means? I did not remember there is such technology in WCF?
George2
@George2: "ozczecho" is the name of the other answerer :-)
marc_s
Thanks for your reply, if I cannot use LINQ (not all of our projects are using .Net 3.5, some are using .Net 3.0, and in .Net 3.0 there is only WCF, no LINQ), how do I implement functions like fetch from the a-th record to b-th record? Any underlying ADO.Net function we could take use of?
George2
@George2: Are you working against SQL Server 2005 or higher? Check out the Common Table Expressions (CTE) which are basically the basis for what LINQ does. This allows you to define "virtual" view on your data and select only a certain section of the data set.
marc_s
@George2 : If I'm not mistaken, LINQ was big part of .NET 3.0 - should be there!
marc_s
I am working with SQL Server 2008, but I do not want to dependent on LINQ, because some of my legacy application is using .Net 2.0. In this scenario, how to implement the function which could fetch specified range of rows?
George2