This sample uses the
WCF REST Starter Kit Preview 2 to build a REST service. The Starter Kit offers an
Atom Publishing Protocol WCF Service project template which contains a basic
AtomPub implementation. AtomPub is a protocol to manage a collection of Atom entries via HTTP verbs. It also supports adding media entries (images, etc) to the collection using HTTP verbs.
Here is the feed representing the collection of entries stored.
In this implementation, the template provides the basic functionality to manage the entries in the collection. The storage for the Atom entries and any media entries is provided by the Azure storage service. Atom entries are stored in Table Storage, and media entries are stored in Blob Storage. This helps us maintain the state of the AtomPub service - any changes made by a given user will seen by subsequent users.
The AtomPub service created can be accessed via HTTP verbs. For example, you can access the URI of any item in collection by simply typing in its URI in the browser, which effectively sends a HTTP GET to that entry. While you can use tools such as
Fiddler to send HTTP requests and work with the service, there is no easy way to access the service from code. The Starter Kit addresses this by providing a specialized class called
AtomPubClient. Effectively this tool dispatches HTTP requests, but it abstracts away the exact details of the AtomPub protocol. The user just calls easy methods such as
AddEntry and
AddMediaResource, and the AtomPubClient issues the appropriate HTTP requests. In this sample we include a console client implementation, which uses AtomPubClient to exercise the AtomPub service.
Here is a quick walkthrough of the steps taken to build this solution:
- Create new Web Cloud Service project called PictureRestService
- We now want to add the AtomPub service to the PictureRestService_WebRole project. Use the workaround mentioned under Hosting WCF REST Services > Using project templates from the Starter Kit on the KnownIssues page
- We now need to modify the default AtomPub service so that it works on Azure. Follow the steps under Hosting WCF REST Services > Configuring the base address on the KnownIssues page to create an AzureAtomPubServiceHost
- Copy over the StorageClient project from the Azure SDK - this provides a convenient set of classes to access the Azure storage services
- Now you can begin to implement the logic in the Service.svc.cs file so it uses the Azure storage services, as shown in the reference code for this sample
- Once the service development is complete, we need to create a client, so we can test the service. Add a new Console Applicaiton project to the solution and name it HttpClient.
- Add references to the Microsoft.Http and Microsoft.Http.Extensions assemblies to the project
- You can now use the Microsoft.Http.AtomPubClient class and methods such as AddEntry() and AddMediaResource() to talk to the service
- To run the service in the local fabric:
- Please ensure that the information in Web.config and ServiceConfiguration.cscfg is correct
- Before using it, you need to create tables inside Table Storage that match the data types that will be stored. Those types are contained in the StorageServiceTypes.cs file. The sample contains logic to create the types in the cloud fabric, however the local fabric has the limitation that these tables need to be created manually by using the devtablegen.exe tool, part of the Azure SDK. The syntax would be: devtablegen PictureService_WebRole.dll /database YourDatabaseName
- To run the service in the cloud fabric, please update the information in Web.config and ServiceConfiguration.cscfg to reflect your account settings. Note that in order to update ServiceConfiguration.cscfg you need to first deploy the service using the Azure portal, and then use the Configure button, which will let you edit the file.
Demo Service This exposes the feed for the collection stored by the service. You may want to select
View Source in order to see the full details of the Atom feed, the feed reader provided in the browser frequently hides away some of the information in the feed. You can run the client provided in the sample against this service in order to explore how AtomPub works.
Here is the final result showing the feed exposing the collection stored by the service. A media item is attached to the top post and clicking the link shows the media item.
Here is the result of running the console client: