Returning Large Volume of Records from SOAP based WCF Service
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
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
- One Operation contract. This function will pull large data from database using stored procedure.
- One Data Contract. This class will act as Data Transfer object (DTO) between client and service.
- 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 {
[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();
}
List<DTOClass> GetData();
}
- Service is returning List of DTOClass.
- 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);
}
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; ;
}
} }
}
} }
- This is simple implementation. Where ADO.Net is being used to fetch data from Database.
- 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
Configuration setting at service side
See full details: http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/179/
Comments
Online Dot Net Training
.net online Training
C# Training
ASP NET Training
Entity Framework Training