Exercise: Make your own RESTful web service

In this exercise you must program your own RESTful service provider, test it and publish it in Azure.

The service must provide information about students (and maybe other school related resources later ...)

Getting started

In Visual Studio make a new project type WCF -> WCF Service Application (same type as you used for SOAP).

Add a Unit test project to the solution and make sure the Unit test project refers to the "main" project.

Adapt the web.config file to support REST (not SOAP)

Create serviceBehavior and endpointBehavior for REST (not SOAP)

http://stackoverflow.com/questions/17644392/configuring-wcf-rest-services-in-web-config

Disable WSDL file generation

serviceMetadata httpGetEnabled="false"

Iterations: Interface, implementation, run, try, test

Now you should get into a set of small and quick (hopefully) iteration. In each iteration you must:

  1. Add ONE new method to the service interface.
    Which HTTP method/verb to use?
    What should the URI (UriTemplate) look like? Any parameters to the URI, like {id}?
    What is the request format (RequestFormat)? JSON or XML, or not necessary at all.
    What is the response format (ResponseFormat)? JSON or XML, or not necessary at all.
  2. Implement the method.
    Use a static collection to hold data: Example private static readonly IList<Book> Books = new List<Book>();
  3. Run the service locally in the Azure emulator.
  4. Try the service using Postman.
    WCFTestClient works with SOAP only, not REST.
  5. Unit test the method by calling the method directly from the implementing class (no network required).
    Make sure the test has a good "Code Coverage".

Publish to Azure

Publish your service in Azure.
Don't forget to lower the .NET version to 4.0 to please Azure!?

Try the service using Postman.

Use WireShark to observe the requests and responses.

Extra: Integration test

You already unit tested the methods of the implementing class.

Now you should do integration test: Make another test project and test the service running in Azure.

Extra: Database

Refactoring: Skip the static collection and keep the data in a database hosted in Azure.

Extra: Continuous integration and delivery

In Microsoft Team Services setup a build for your REST service.

Note on Setup a build server