Tuesday, August 18, 2015

RESTful WCF Services

We will understand steps with an example of maintaining players list

Steps to create Wcf REST service 
  1. It requires webHttpBinding.
  2. It requires <webHttp />  tag inside behavior tag.
  3. Create wcf service application
  4. Create methods for add, update, delete, get player
            Player GetPlayer(string id);
            void AddPlayer(string name);
            void UpdatePlayer(string id, string name);
            void DeletePlayer(string id);
            List<Player> GetPlayers();
  5. Mark created methods with below given methods
                 1. WebGet
                 2. WebInvoke

  6. Assign values of parameters in WebGet and WebInvoke as required
    • UriTemplate : Set url format to access the method
      • GetPlayer/{id}
      • UpdatePlayer/{id}/{name}
    • Method
      • POST : To submit data to process
      • PUT : To update resource
      • DELETE : To delete resource
    • RequestFormat
      • RequestFormat= WebMessageFormat.Xml
      • RequestFormat= WebMessageFormat.Json
    • ResponseFormat
      • ResponseFormat= WebMessageFormat.Xml
      • ResponseFormat= WebMessageFormat.Json
    • BodyStyle
      • Bare
      • Wrapped
      • WrappedRequest
      • WrappedRespons






   
5. Service config settings
Note : In below given config settings 4th & 5th points are not compulsory.






No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...