protected override Task<HttpResponseMessage> SendAsync(
            HttpRequestMessage request, 
            CancellationToken cancellationToken) {

            UrlHelper url = request.GetUrlHelper();
            ServiceDocument doc = new ServiceDocument();
            Workspace ws = new Workspace() {

                Title = new TextSyndicationContent("My Site"),
                BaseUri = new Uri(request.RequestUri.GetLeftPart(UriPartial.Authority))
            };

            ws.Collections.Add(GetPostsResourceCollectionInfo(url));
            ws.Collections.Add(GetMediaResourceCollectionInfo(url));
            doc.Workspaces.Add(ws);

            HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK);
            var formatter = new AtomPub10ServiceDocumentFormatter(doc);

            var stream = new MemoryStream();
            using (var writer = XmlWriter.Create(stream)) {
                formatter.WriteTo(writer);
            }

            stream.Position = 0;
            var content = new StreamContent(stream);
            response.Content = content;
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/atomsvc+xml");

            return Task.FromResult(response);
        }
		public void WriteTo ()
		{
			var s = new ServiceDocument ();
			var a = new AtomPub10ServiceDocumentFormatter (s);
			Assert.AreEqual ("http://www.w3.org/2007/app", a.Version, "#1");
			Assert.IsTrue (a.CanRead (XmlReader.Create (new StringReader (app1))), "#2");
			var sw = new StringWriter ();
			using (var xw = XmlWriter.Create (sw, settings))
				a.WriteTo (xw);
			Assert.AreEqual (app1, sw.ToString (), "#3");
		}
        public HttpResponseMessage Get()
        {
            var doc = new ServiceDocument();
            var ws = new Workspace
            {
                Title = new TextSyndicationContent("My Site"),
                BaseUri = new Uri(Request.RequestUri.GetLeftPart(UriPartial.Authority))
            };

            var posts = new ResourceCollectionInfo("Blog",
                new Uri(Url.Link("DefaultApi", new { controller = "posts" })));

            posts.Accepts.Add("application/atom+xml;type=entry");

            // For WLW to work we need to include format in the categories URI.
            // Hoping to provide a better solution than this.
            var categoriesUri = new Uri(Url.Link("DefaultApi", new { controller = "tags", format = "atomcat" }));
            var categories = new ReferencedCategoriesDocument(categoriesUri);
            posts.Categories.Add(categories);

            ws.Collections.Add(posts);

            doc.Workspaces.Add(ws);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            var formatter = new AtomPub10ServiceDocumentFormatter(doc);

            var stream = new MemoryStream();
            using (var writer = XmlWriter.Create(stream))
            {
                formatter.WriteTo(writer);
            }

            stream.Position = 0;
            var content = new StreamContent(stream);
            response.Content = content;
            response.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/atomsvc+xml");

            return response;
        }
		public void WriteTo2 ()
		{
			var s = new ServiceDocument ();
			var ws = new Workspace ("test title", null);
			var rc = new ResourceCollectionInfo ("test resource", new Uri ("urn:foo"));
			rc.Accepts.Add ("application/atom+xml;type=entry");
			ws.Collections.Add (rc);
			s.Workspaces.Add (ws);
			var a = new AtomPub10ServiceDocumentFormatter (s);
			Assert.AreEqual ("http://www.w3.org/2007/app", a.Version, "#1");
			Assert.IsTrue (a.CanRead (XmlReader.Create (new StringReader (app2))), "#2");
			var sw = new StringWriter ();
			using (var xw = XmlWriter.Create (sw, settings))
				a.WriteTo (xw);
			Assert.AreEqual (app2, sw.ToString (), "#3");
		}