fatima2007
چهارشنبه 16 اردیبهشت 1394, 14:54 عصر
سلام
من یه پروژه دارم می نویسم با WCF rest service که کار ارتباط با دیتابیس رو انجام میده ( select,update,delete,insert) و باید به صورت معماری لایه ای پیاده سازی بشه. در نهایت توسط یک کلاینت استفاده بشه. مثلا برای خواندن از دیتابیس از جدول t_archive یه همچین کارهایی باید انجام بدم. یه پوشه دارم به اسم BO که کلاس داده ها توش تعریف میشن.
public class Meta
}
[DataMember]
{ ; public int Id { get; set
[DataMember]
{; public string Title { get; set
[DataMember]
{; public string AlbumTitle { get; set
[DataMember]
{; public string EpisodeTitle{ get; set
{
یه پوشه دارم به اسم DAL که کار ارتباط با دیتابیس رو انجام میده.
public class Meta
{
public static BO.Meta SelectById(int Id)
{
var MetaData = new BO.Meta();
var sqlCommand = new SqlCommand();
sqlCommand.CommandText = @"Select top(50) * from T_Archive_Meta where ID="+Id+"";
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Connection = new SqlConnection(WebConfigurationManager.ConnectionSt rings["Archive-Str"].ToString());
try
{
sqlCommand.Connection.Open();
var Dr = sqlCommand.ExecuteReader();
while (Dr.Read())
{
var Meta = new BO.Meta();
Meta.Id = int.Parse(Dr["ID"].ToString());
Meta.Title = Dr["Title"].ToString();
Meta.AlbumTitle = Dr["AlbumTitle"].ToString();
Meta.EpisodeTitle = Dr["EpisodeTitle"].ToString();
//MetaList.Add(Meta);
}
}
catch (Exception ex)
{
}
finally
{
sqlCommand.Connection.Close();
sqlCommand.Dispose();
}
return MetaData;
}
یه پوشه هم دارم که توابع رو فراخوانی میکنه به نام BLL
public class Meta
}
public static BO.Meta SelectById(int Id)
}
( return DAL.Meta.SelectById(Id
{
{
دوتا فایل دیگه هم دارم یکی به نام
IMeta
شامل
public interface IMeta
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
[( "{UriTemplate = "/{Id
; ( BO.Meta SelectById(string Id
و فایل
Meta.svc
شامل
( public BO.Meta SelectById(string Id
}
((var Obj = BLL.Meta.SelectById(int.Parse(Id
; return Obj
{
این وب سرویس به دیتایبیس وصل میشه و با گرفتن ای دی، مشخصات رکورد موردنظر رو میده
الان نمیدونم توی کلاینتم جچوری از این وب سرویس استفاده کنم
میخوام یک گرید داشته باشم که با این داده ها پر بشه
ولی نمیدونم باید از چه کدی استفاده کنم در کلاینت
ضمنا خروجی باید به صورت json به کلاینت فرستاده بشه
ممنون میشم راهنماییم کنید
من یه پروژه دارم می نویسم با WCF rest service که کار ارتباط با دیتابیس رو انجام میده ( select,update,delete,insert) و باید به صورت معماری لایه ای پیاده سازی بشه. در نهایت توسط یک کلاینت استفاده بشه. مثلا برای خواندن از دیتابیس از جدول t_archive یه همچین کارهایی باید انجام بدم. یه پوشه دارم به اسم BO که کلاس داده ها توش تعریف میشن.
public class Meta
}
[DataMember]
{ ; public int Id { get; set
[DataMember]
{; public string Title { get; set
[DataMember]
{; public string AlbumTitle { get; set
[DataMember]
{; public string EpisodeTitle{ get; set
{
یه پوشه دارم به اسم DAL که کار ارتباط با دیتابیس رو انجام میده.
public class Meta
{
public static BO.Meta SelectById(int Id)
{
var MetaData = new BO.Meta();
var sqlCommand = new SqlCommand();
sqlCommand.CommandText = @"Select top(50) * from T_Archive_Meta where ID="+Id+"";
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Connection = new SqlConnection(WebConfigurationManager.ConnectionSt rings["Archive-Str"].ToString());
try
{
sqlCommand.Connection.Open();
var Dr = sqlCommand.ExecuteReader();
while (Dr.Read())
{
var Meta = new BO.Meta();
Meta.Id = int.Parse(Dr["ID"].ToString());
Meta.Title = Dr["Title"].ToString();
Meta.AlbumTitle = Dr["AlbumTitle"].ToString();
Meta.EpisodeTitle = Dr["EpisodeTitle"].ToString();
//MetaList.Add(Meta);
}
}
catch (Exception ex)
{
}
finally
{
sqlCommand.Connection.Close();
sqlCommand.Dispose();
}
return MetaData;
}
یه پوشه هم دارم که توابع رو فراخوانی میکنه به نام BLL
public class Meta
}
public static BO.Meta SelectById(int Id)
}
( return DAL.Meta.SelectById(Id
{
{
دوتا فایل دیگه هم دارم یکی به نام
IMeta
شامل
public interface IMeta
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
[( "{UriTemplate = "/{Id
; ( BO.Meta SelectById(string Id
و فایل
Meta.svc
شامل
( public BO.Meta SelectById(string Id
}
((var Obj = BLL.Meta.SelectById(int.Parse(Id
; return Obj
{
این وب سرویس به دیتایبیس وصل میشه و با گرفتن ای دی، مشخصات رکورد موردنظر رو میده
الان نمیدونم توی کلاینتم جچوری از این وب سرویس استفاده کنم
میخوام یک گرید داشته باشم که با این داده ها پر بشه
ولی نمیدونم باید از چه کدی استفاده کنم در کلاینت
ضمنا خروجی باید به صورت json به کلاینت فرستاده بشه
ممنون میشم راهنماییم کنید