PDA

View Full Version : Gọi phương thức từ WebService vào trang web



ngocquy_ytc
16-05-2009, 12:30
Em có 1 cái WebService có phương thức GetCustomer() kiểu trả về là Dataset.
Em tạo 1 trang web(Gồm 1 button,1 GridView) để gọi phương thức GetCustomer() từ WebService nhưng chạy thì nó ko hiện lên dữ liệu.
Em thử chạy WebService để Test thì nó có kết quả:

Code use WebService như sau:

protected void btnView_Click(object sender, EventArgs e)
{
Service.Service a = new Service.Service();
GridView1.DataSource= a.GetCustomer().Tables["Customers"];
GridView1.DataBind();
}
Code trên có sai gì ko mấy anh. Có code nào để Bind dữ liệu nữa ko mấy anh

dq_ninh
16-05-2009, 14:04
Em có 1 cái WebService có phương thức GetCustomer() kiểu trả về là Dataset.
Em tạo 1 trang web(Gồm 1 button,1 GridView) để gọi phương thức GetCustomer() từ WebService nhưng chạy thì nó ko hiện lên dữ liệu.
Em thử chạy WebService để Test thì nó có kết quả:

Code use WebService như sau:

protected void btnView_Click(object sender, EventArgs e)
{
Service.Service a = new Service.Service();
GridView1.DataSource= a.GetCustomer().Tables["Customers"];
GridView1.DataBind();
}
Code trên có sai gì ko mấy anh. Có code nào để Bind dữ liệu nữa ko mấy anh

Code trên khòng có gì sai, nhưng chưa đủ để đưa dữ liệu từ web-server về client page.

Cái khó duy nhất của những lập trình cho web là sự phân biệt giữa những code chạy tại server và những code chạy trên client pages.

Bạn cần phải có một Proxy class để đưa những dữ liệu từ server về client page. Google cho Web-service, proxy class, bạn sẽ tìm thấy những sample code để đưa dữ liệu từ GetCustomer() về gridview.