Consuming a web service
Now that you learned how to publish and receive XML and JSON formatted messages, it's time to explore how to consume a RESTful service.
For our REST service, we will use Visual Studio to create a Web API project using the ASP.Net MVC 4 web application template. This creates the following stub code for each HTTP verb:
// GET api/values public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET api/values/5 public string Get(int id) { return "value"; } // POST api/values public void Post([FromBody]string value) { } // PUT api/values/5 public void Put(int id, [FromBody]string value) { } // DELETE api/values/5 public void Delete(int id) { }
The preceding code creates the default API methods as shown in the following screenshot. Next, we will show how you can call some of these resources using the WCF-WebHttp send adapter:
Let's now set up a send port to use the WCF-WebHttp adapter to make a simple GET request to our sample web service...