Restful services-slides

1,070 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,070
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Restful services-slides

  1. 1.        
  2. 2.       
  3. 3.      
  4. 4.         
  5. 5.  getUser() addUser() removeUser() ... getLocation() addLocation() ... User { } Location { } <user> <name>Jane User</name> <gender>female</gender> <location href="http://example.org/locations/us/ny/nyc" >New York City, NY, US</location> </user>
  6. 6.          
  7. 7.       
  8. 8.         
  9. 9.          
  10. 10.  
  11. 11.        
  12. 12.        
  13. 13. ... ServiceHost host = new ServiceHost(typeof(EvalService), new Uri("http://localhost:8080/evals")); host.AddServiceEndpoint(typeof(IEvals), new WebHttpBinding(), ""); host.Description.Endpoints[0].Behaviors.Add( new WebHttpBehavior()); host.Open(); // service is up and running Console.ReadLine(); // hold process open ...
  14. 14.     ... WebServiceHost host = new WebServiceHost( typeof(EvalService), new Uri("http://localhost:8080/evals")); host.Open(); // service is up and running Console.ReadLine(); // hold process open ...
  15. 15.      [ServiceContract] public interface IEvalService { [WebGet(UriTemplate="evals?name={name}&score={score}")] [OperationContract] List<Eval> GetEvals(string name, int score); ...
  16. 16.     [ServiceContract] public interface IEvals { [WebInvoke(UriTemplate ="/evals?name={name}",Method="PUT")] [OperationContract] void SubmitEval(string name, Eval eval /* body */); ...
  17. 17.      /services/evals?name={name}&detailed={detailed}
  18. 18.     
  19. 19.      
  20. 20.      [ServiceKnownType(typeof(Atom10FeedFormatter))] [ServiceKnownType(typeof(Rss20FeedFormatter))] [ServiceContract] public interface IEvalService { [WebGet(UriTemplate = "evalsfeed")] [OperationContract] SyndicationFeedFormatter GetEvalsFeed(); ... }
  21. 21. public class EvalService : IEvalService { public SyndicationFeedFormatter GetEvalsFeed() { List<Eval> evals = this.GetEvals(); SyndicationFeed feed = CreateSyndicationFeed(evals); // figure out what format the client wants WebOperationContext ctx = WebOperationContext.Current; string format = ctx.IncomingRequest.UriTemplateMatch.QueryParameters["format"]; // return the if (format != return new else return new } ... right type of formatted feed null && format.Equals("atom")) Atom10FeedFormatter(feed); Rss20FeedFormatter(feed);
  22. 22.   [ServiceContract] public interface IEvals { [WebGet(UriTemplate = "/evals?name={nameFilter}", ResponseFormat = WebMessageFormat.Json)] [OperationContract] List<Eval> GetCurrentEvals(string nameFilter); ...
  23. 23.        <%@ ServiceHost Language="C#" Service="EvalService" Factory= "System.ServiceModel.Activation.WebScriptServiceHostFactory" %>
  24. 24.        
  25. 25.         
  26. 26.      

×