WCF Application
In that
IService.cs page
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Runtime.Serialization;
using
System.ServiceModel;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
// NOTE: If you
change the interface name "IService" here, you must also update the
reference to "IService" in Web.config.
[ServiceContract]
public interface IService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType
GetDataUsingDataContract(CompositeType
composite);
[OperationContract]
DataSet
SampleFillGrid();
// TODO: Add your service operations
here
}
// Use a data
contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool
BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string
StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Runtime.Serialization;
using
System.ServiceModel;
using
System.Text;
using
System.Data;
using System.Data.SqlClient;
using
System.Configuration;
// NOTE: If you
change the class name "Service" here, you must also update the
reference to "Service" in Web.config and in the associated .svc file.
public class Service : IService
{
SqlConnection
con;
SqlCommand
cmd;
SqlDataAdapter
sqlda;
DataTable
dt;
DataSet
ds;
public string
GetData(int value)
{
return string.Format("You
entered: {0}", value);
}
public CompositeType
GetDataUsingDataContract(CompositeType
composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
public DataSet SampleFillGrid()
{
string
conStr = ConfigurationManager.ConnectionStrings["mydbCon"].ConnectionString;
string
selQry = "select * from employeeDB";
using
(con = new SqlConnection(conStr))
{
con.Open();
using
(cmd = new SqlCommand(selQry,
con))
{
sqlda = new SqlDataAdapter(cmd);
DataTable
dtT = new DataTable();
ds = new
DataSet();
sqlda.Fill(ds, "employeeDB");
return
ds;
}
}
}
}
Run
using System;
using
System.Collections;
using
System.Configuration;
using
System.Data;
using
System.Linq;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.HtmlControls;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Xml.Linq;
using
SampleWCFService;
using
System.Text;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
if (!IsPostBack)
{
FillGrid();
}
}
private void FillGrid()
{
SampleWCFService.ServiceClient swcf = new
SampleWCFService.ServiceClient();
GridView1.DataSource=
swcf.SampleFillGrid();
GridView1.DataBind();
}
}
Comments
Post a Comment