Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 4th, 2012  |  syntax: None  |  size: 1.17 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. WCF WebHttp Service using POCO from EntityFramework 4.1 - dbContext
  2. [ServiceContract]
  3. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  4. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  5. public class SearchService
  6. {
  7.  
  8.     [WebGet(UriTemplate = "Students")]
  9.     public List<coop_Students> GetStudents()
  10.     {
  11.         List<string> ret = new List<string>();
  12.  
  13.         CottageDataEntities db = new CottageDataEntities();
  14.         var students = from s in db.coop_Students
  15.                        where s.status == "enrolled"
  16.                        orderby s.lastname, s.firstname
  17.                        select s;
  18.         return students.ToList();
  19.  
  20.     }
  21.  
  22.     [WebGet(UriTemplate = "Echo/{text}")]
  23.     public string Echo(string text)
  24.     {
  25.         return "Hello " + text;
  26.     }
  27.  
  28.     [WebGet(UriTemplate = "Students/{studentID}")]
  29.     public coop_Students GetStudent(string studentID)
  30.     {
  31.         using (CottageDataEntities db = new CottageDataEntities())
  32.         {
  33.             int id = int.Parse(studentID);
  34.             var student = db.coop_Students.FirstOrDefault(s => s.studentID == id);
  35.             return student;
  36.         }
  37.     }
  38. }