You can create webservice(.asmx) like this one
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class GetDataWebService : System.Web.Services.WebService
{
BooksDBEntities db = new BooksDBEntities();
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public List<studentserialized> GetAllStudentData()
{
List<student> lststu = new List<student>();
lststu = db.Students.ToList();
List<studentserialized> lstss = new List<studentserialized>();
foreach (Student sss in lststu)
{
StudentSerialized ss = new StudentSerialized();
ss.ID = sss.ID;
ss.Name = sss.Name;
ss.Roll = sss.Roll;
lstss.Add(ss);
}
return lstss;
}
public class StudentSerialized
{
public int ID { get; set; }
public string Name { get; set; }
public string Roll { get; set; }
}
}
This function(GetAllStudentData) will return an XML.
<arrayofstudentserialized xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<studentserialized>
<id>1</id>
<name>Anis</name>
<roll>0718004</roll>
</studentserialized>
<studentserialized>
<id>2</id>
<name>Toma</name>
<roll>0718040</roll>
</studentserialized>
<studentserialized>
<id>3</id>
<name>Bachchu</name>
<roll>0717007</roll>
</studentserialized>
</arrayofstudentserialized>