topical media & game development

talk show tell print

#mobile-application-03-DerbyNamesService-DerbyNamesService-DerbyService.cs / cs



  using System;
  using System.Linq;
  using System.ServiceModel;
  using System.ServiceModel.Activation;
  using System.ServiceModel.Web;
  using System.Collections.Generic;
  using System.Net;
  using System.IO;
  using System.Text;
  
  namespace DerbyNamesService
  {
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
      [ServiceContract]
      public class DerbyService 
      {
          [WebGet]
          public IEnumerable<DerbyNames> PlayerNames()
          {
              var names = new DerbyContext().DerbyNames.Take(5).ToList();
              return names;
          }
  
          [WebGet]
          public IEnumerable<Leagues> Leagues()
          {
              var leagues = new DerbyContext().Leagues.ToList();
              return leagues;
          }
  
          [WebGet(UriTemplate="*")]
          public void ErrorForGet()
          {
              throw new WebFaultException(HttpStatusCode.NotFound);
          }
  
          [WebGet(UriTemplate="")]
          public Stream Root()
          {
              WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
              string html = "<a href=\"PlayerNames\">Player Names</a><br /><a href=\"Leagues\">Leagues</a>";
              return new MemoryStream(Encoding.UTF8.GetBytes(html));
          }
  
      }
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.