Below iservice.svs.cs code how to use xml document in foreach class.is there any possible other way
iservice.cs
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetAllEmployee/")]
List<Class1> GetAllEmployee();
}
<pre lang="cs">[DataContract]
public class Class1
{
[DataMember]
public string empid { get; set; }
[DataMember]
public string empname { get; set; }
[DataMember]
public string empage { get; set; }
[DataMember]
public string emplocation { get; set; }
}</pre>
iservice.svs.cs
<pre lang="xml">public class Service1 : IService1
{
public List<Class1> GetAllEmployee()
{
List<Class1> empList = new List<Class1>();
XmlDocument doc = new XmlDocument();
doc.Load(System.Web.HttpContext.Current.Server.MapPath("E:\\grid_wcf\\emp.xml"));
foreach (var employee in employees)
{
empList.Add(new Class1
{
empid = employee.Element("empid").Value,
empname = employee.Element("empname").Value,
empage = employee.Element("empage").Value,
emplocation = employee.Element("emplocation").Value
});
}
return empList;
}
}</pre>