Beruflich Dokumente
Kultur Dokumente
Objectives
1. Create WCF service (host on web server ) 2. Using WCF service from window form application
Hits: Step for create and using service
Create WCF service Student with two operations list() and detail(id) Define service interface (ServiceContract) Define class describe detail of student (DataContract) Define Service by implement from server interface
Using WCF service from window form application Find service description of WCF student Reference WCF service Call operations of student service
Student table
No. 1. 2. 3. 4. Data field S_ID S_FullName S_Birthdate S_Address Data type Int Text DateTime Text
CUSC 2013
Page 1
Open visual studio 2008 (or later) File -> Create Project
Select as figure
Select as figure
Modified class as
namespace students { [DataContract] public class StudentDetail { [DataMember] public int ID; [DataMember] public string FullName; [DataMember] public DateTime Birthdate; [DataMember] public string Address; } }
CUSC 2013
Page 3
namespace students { public class Student : IStudent { #region IStudent Members public DataSet List() { DataSet dsS = new DataSet(); // insert C# code to get data from student table return dsS; } public StudentDetail Detail(int ID) { StudentDetail sDetail = new StudentDetail(); // insert C# code to find data from student table with ID from input param // assign value for all properties of sDetail return sDetail; } #endregion } }
wsdl of service
CUSC 2013
Page 4
Select as figure
Design form as
DataGridView
CUSC 2013
Page 6
Client at runtime
CUSC 2013
Page 7