-2

any body can help me regarding

  1. I am having WCF service its working fine
    wcf having database conectivity database having 100 records
    WCF service fetching records from database these records have to submit to the client system when ever client make a request for records.
  2. when client makes the request for records, it works fine for 10-20 records but fetching records 100 due to huge trafic between client and WCF service, service not providing services.

how can we handle this situvation in WCF?

VMAtm
  • 27,943
  • 17
  • 79
  • 125

1 Answers1

2

If it is throwing an exception that the message size is too large you could look at some of the options outlined in this question: Setting Max Message and buffer size for WCF webhttp.

Is 100 records the maximum that your service will return? If it is going to just grow and grow I would not recommend altering the message size. Instead you should probably consider some sort of paging mechanism so if you had a method that looked something like this:

IEnumerable<Record> GetRecords()

make it:

Response GetRecords(index)

Then Response would look like this:

[DataContract]
public class Response
{
    [DataMember]
    IEnumerable<Record> Records { get; set; }

    [DataMember}
    bool IsLast { get; set; }

    [DataMember]
    int PageIndex { get; set }
}

Then you would call it from the client something like this:

Response resp;
int pageIndex = 0;
do
{
    resp = service.GetRecords(pageIndex);
    // use resp.Records here - could just build a bigger list with them all in
    // and use it after the loop or if your client can handle chunks, just use it
    pageIndex = resp.PageIndex + 1;
} while(!resp.IsLast);

Not the most sophisticated paging but it gives you somewhere to start hopefully.

Community
  • 1
  • 1
kmp
  • 10,535
  • 11
  • 75
  • 125