Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » WCF » Returning Large Volume of Records from SOAP based WCF Service

Returning Large Volume of Records from SOAP based WCF Service

In this article I will explain; How to return large volume of data (around 50000 records) from SOAP based WCF service to any client.

Author Rank:
Total page views :  3922
Total downloads : 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Become a Sponsor


Objective

In this article I will explain; How to return large volume of data (around 50000 records) from SOAP based WCF service to any client. I will show; what service configuration setting and client configuration setting is needed to handle large volume of data returning for WCF service.

Follow the below steps,

Step 1: Create a WCF service

.To creates WCF service; select File -> New -> Project-> Web -> WCF Application.
Service will contain

  1. One Operation contract. This function will pull large data from database using stored procedure.
  2. One Data Contract. This class will act as Data Transfer object (DTO) between client and service.
  3. basicHttpBinding is being used in the service. You are free to use any binding as of your requirement.

Data Transfer Class

[DataContract]
    public class DTOClass
    {
        [DataMember]
        public string SystemResourceId
        {
            get;
            set;
        }
        [DataMember]
        public string SystemResourceName
        {
            get;
            set;
        }
        [DataMember]
        public string Created
        {
            get;
            set;
        }
        [DataMember]
        public string Creater
        {
            get;
            set;
        }
        [DataMember]
        public string Updated
        {
            get;
            set;
        }
        [DataMember]
        public string Updater
        {
            get;
            set;
        }



1. Name of DTO class is DTOClass. You can give any name of your choice.
2. There are 6 string properties.
3. All properties are attributed with DataMember.

Contract

   [ServiceContract]
    [ServiceKnownType(typeof(DTOClass))]
    public interface IService1
    {

        [OperationContract]
         List<DTOClass> GetData();
      
    }

 

  1. Service is returning List of DTOClass.
  2. To get serialized at run time, making sure Data Contract is known to contract by using known type.

Service Implementation

public class Service1 : IService1
    {

        string cs = @"Data Source=xxxserver;Initial Catalog=Sampledatabase;User=dhananjay;Password=dhananjay";

        List<DTOClass> restDto = new List<DTOClass>();
        DTOClass dto;

        public List<DTOClass> GetData()
        {
            SqlConnection con = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand("GetAllSystemResourceDetails", con);
            cmd.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(dt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dto = new DTOClass();
                dto.SystemResourceId = dt.Rows[i][0].ToString();
                dto.SystemResourceName = dt.Rows[i][1].ToString();
                dto.Created = dt.Rows[i][8].ToString();
                dto.Updated = dt.Rows[i][10].ToString();
                dto.Creater = dt.Rows[i][9].ToString();
                dto.Updater = dt.Rows[i][11].ToString();               
                restDto.Add(dto);           
            }

            return restDto; ;
        }
} }

  1. This is simple implementation. Where ADO.Net is being used to fetch data from Database.
  2. GetAllSystemResourceDetails is name of the stored procedure.

Note: Purpose of this article is to show how to push large volume of data from WCF service. So, I am not emphasizing ADO.Net part here. See the other articles for detail explanation on ADO.Net

Configuration setting at service side

<system.serviceModel>
  <
services>
<
service name="TestingLargeData.Service1"     behaviorConfiguration="TestingLargeData.Service1Behavior">                   
<endpoint address="" binding="basicHttpBinding" contract="TestingLargeData.IService1" bindingConfiguration="LargeBuffer">                              <identity>
                        <
dns value="localhost"/>
                        </identity>
</
endpoint>
<
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</
services>
<
behaviors>
<
serviceBehaviors>
<
behavior name="TestingLargeData.Service1Behavior">                          
<serviceMetadata httpGetEnabled="true"/>                         
<serviceDebug includeExceptionDetailInFaults="false"/>
 <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
 </behavior>
</
serviceBehaviors>
</
behaviors>
   
<bindings>
      <
basicHttpBinding>
        <
binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
           maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </
bindings>
  </
system.serviceModel>

  1. In service behavior, for dataContractSerializer I am increasing the number of object that can be serialized or de serialized at a time. By default it is set to 3565. Since our requirement is to push or return large volume of data, so I am giving value for maxItemsInObjectGraph to maximum integer number.
  2. Since, I am using basicHttpBinding, so I am modifying values for this binding. I am setting all the attributes to maximum integer value.
  3. Binding I am using is basicHttpBinding.

Compile the service and run to test, whether service is successfully created or not?

Step 2: Creating a client and Consuming the service.

Create any type of client. For my purpose I am creating a console client. After creating a console project, right click at Service Reference and add service reference. While adding service reference make sure, in advance setting as collection type System.Collection.Generic.List is selected.

image1.gif

Configuration setting at client side

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <
system.serviceModel>
        <
bindings>
            <
basicHttpBinding>
                <
binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">                   
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </
binding>
            </
basicHttpBinding>
        </
bindings>
        <
client>
           
<endpoint address="http://localhost:55771/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1"  behaviorConfiguration ="r1"/>
        </client>
     
<behaviors>
        <
endpointBehaviors>
          <
behavior name ="r1">
            <dataContractSerializer maxItemsInObjectGraph ="2147483647"/>
          </behavior>
        </
endpointBehaviors>
      </
behaviors>
    </system.serviceModel>
</
configuration>

  1. Attributes of basicHttpBinding has been modified for the maximum integer values.
  2. In endpoint behavior maxItemsInObjectGraph for dataContractSerializer has been modified to maximum integer value.

Program.cs

class Program
    {
        static void Main(string[] args)
        {
            Service1Client proxy = new Service1Client();
            List<DTOClass> res = new List<DTOClass>();
            res = proxy.GetData();
           
            foreach (DTOClass  i in res)
            {
                Console.WriteLine(i.SystemResourceId + i.SystemResourceName + i.Updated + i.Updater);

             
            }
            Console.Read();
        }}}



Conclusion

In this article, I explained how we can return large volume of data from WCF service and how at client side large volume of data can be consumed. This article explained on WCF SOAP based service. Next article I will explain how to achieve same for WCF REST service. Thanks for reading.


Login to add your contents and source code to this article
 About the author
 
Dhananjay Kumar
I am Dhananjay Kumar. I passed computer science  & engineering from AEC Agra in year 2007. I born and brought up in Jamshedpur , Jharkhand.I am MCTS on WCF, MOSS Development , .Net Framework 2.0 Web Application so far. I read and write on WCF, SilverLight , SharePoint , ASP.Net MVC, ASP.Net 3.5 Extensions , .Net 4.0 , C# 3.0 , C# 4.0 etc etc. Currently , I am working for UST Global as Software Engineer and active member of Microsoft COE team .
 
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
 
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
Click Here for 6 Months Free! Powerful ASP.NET Hosting at your Fingertips!
Become a Sponsor
 Comments
Easy to understand example by Kevin On January 30, 2010
Great example and straight to the point.
Good work!
Reply | Email | Delete | Modify | 
Re: Easy to understand example by Dhananjay On February 5, 2010
Thank you :)
Reply | Email | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.