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

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 2.80 KB  |  hits: 12  |  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. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7. using System.ServiceModel.Web;
  8.  
  9. namespace ConsoleApplication.Services
  10. {
  11.     /// <summary>
  12.     ///
  13.     /// </summary>
  14.     public class DemoDataService : IDemoDataService
  15.     {
  16.         /// <summary>
  17.         ///
  18.         /// </summary>
  19.         /// <returns></returns>
  20.         public DemoData Read(string id)
  21.         {
  22.             var ctx = WebOperationContext.Current;
  23.  
  24.             try
  25.             {
  26.                 DemoData data = new DemoData(){Id = Convert.ToInt32(id), Name = "John Doe"};
  27.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
  28.  
  29.                 return data;
  30.                
  31.             }
  32.             catch
  33.             {
  34.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest;
  35.                 return null;
  36.             }
  37.         }
  38.  
  39.         /// <summary>
  40.         ///
  41.         /// </summary>
  42.         /// <param name="newData"></param>
  43.         /// <returns></returns>
  44.         public void Create(DemoData newData)
  45.         {
  46.             var ctx = WebOperationContext.Current;
  47.  
  48.             try
  49.             {
  50.                 DemoData data = new DemoData(){Id = newData.Id, Name = newData.Name};
  51.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
  52.  
  53.                 return;
  54.                
  55.             }
  56.             catch
  57.             {
  58.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NoContent;
  59.                 return;
  60.             }
  61.         }
  62.  
  63.         /// <summary>
  64.         ///
  65.         /// </summary>
  66.         /// <param name="id"></param>
  67.         /// <param name="modifiedData"></param>
  68.         public void Update(string id, DemoData modifiedData)
  69.         {
  70.             var ctx = WebOperationContext.Current;
  71.  
  72.             try
  73.             {
  74.                 modifiedData.Id = Convert.ToInt32(id);
  75.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
  76.  
  77.                 return;
  78.                
  79.             }
  80.             catch
  81.             {
  82.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NoContent;
  83.                 return;
  84.             }
  85.         }
  86.  
  87.         /// <summary>
  88.         ///
  89.         /// </summary>
  90.         /// <param name="id"></param>
  91.         public void Delete(string id)
  92.         {
  93.             var ctx = WebOperationContext.Current;
  94.  
  95.             try
  96.             {
  97.                 int deleteId = Convert.ToInt32(id);
  98.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK;
  99.  
  100.                 return;
  101.                
  102.             }
  103.             catch
  104.             {
  105.                 ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NoContent;
  106.                 return;
  107.             }
  108.         }
  109.        
  110.     }
  111. }