1. 데이터가 들어갈 WebService 프로젝트를 만듭니다.
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.ComponentModel;
using System.Collections;
namespace WebService
{
[ToolboxItem(false)] public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public List<Student> GetCompany()
{
SqlConnection conn = new SqlConnection("server=[서버];database=[DB명];uid=[ID];pwd=[PWD]");
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from Student";
SqlDataAdapter ad = new SqlDataAdapter();
ad.SelectCommand = cmd;
DataSet ds = new DataSet();
ad.Fill(ds);
List<Student> studentlist;
studentlist = new List<Student>();
foreach (DataRowView rw in ds.Tables[0].Rows)
{
Student std = new Student();
std.name = rw["Name"].ToString();
std.age=rw["Age"].ToString();
studentlist.Add(std);
}
return studentlist;
}
}
public class Student
{
public string name {get; set;}
public string age {get; set;}
}
}
2. Silverlight 에 바인딩
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.Collections.ObjectModel;
namespace Demo
{
public MainPage()
{
InitializeComponent();
studentList = new List<Student>();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
StudentListService.CompanyListSoapClient com = new StudentListService.StudentListSoapClient();
com.GetStudentCompleted += new EventHandler<StudentListService.GetStudentCompletedEventArgs>(com_GeStudentCompleted);
com.GetStudentAsync();
}
void com_GetStudentCompleted(object sender, StudentListService.GetStudentCompletedEventArgs e)
{
// 바인딩
}
}
'Silverlight > Tip' 카테고리의 다른 글
DataGrid 해당 Column Sorting 기능 넣기 (0) | 2010.10.12 |
---|---|
[Silverlight 4.0] Print 기능 구현하기 (0) | 2010.08.07 |
Silverlight Tip Site (0) | 2010.07.28 |