Domanda

I'm trying to create an Atompub service with ASP.NET WEB API, all it's ok but when I try to post any image from Windows Live Writer I get an error "The blog doesn't allow the image load" I'm reading the ietf doc.

My services controller code:

public class ServicesController : ApiController
{
    public HttpResponseMessage Get()
    {
        var serviceDocument = new ServiceDocument();
        var workSpace = new Workspace
        {
            Title = new TextSyndicationContent("Nicoloco Site"),
            BaseUri = new Uri(Request.RequestUri.GetLeftPart(UriPartial.Authority))
        };
        var posts = new ResourceCollectionInfo("Nicoloco Blog",
                                               new Uri(Url.Link("DefaultApi", new { controller = "blogapi" })));
        posts.Accepts.Add("application/atom+xml;type=entry");
        var images = new ResourceCollectionInfo("Images Blog",
                                                new Uri(Url.Link("DefaultApi", new { controller = "images" })));
        images.Accepts.Add("image/png");
        images.Accepts.Add("image/jpeg");
        images.Accepts.Add("image/jpg");
        images.Accepts.Add("image/gif");
        var categoriesUri = new Uri(Url.Link("DefaultApi", new { controller = "tags", format = "atomcat" }));
        var categories = new ReferencedCategoriesDocument(categoriesUri);
        posts.Categories.Add(categories);
        workSpace.Collections.Add(posts);
        workSpace.Collections.Add(images);
        serviceDocument.Workspaces.Add(workSpace);
        var response = new HttpResponseMessage(HttpStatusCode.OK);
        var formatter = new AtomPub10ServiceDocumentFormatter(serviceDocument);
        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;
    }
}

The http GET Request generate the follow XML:

<?xml version="1.0" encoding="utf-8"?>
<app:service 
    xmlns:a10="http://www.w3.org/2005/Atom" 
    xmlns:app="http://www.w3.org/2007/app">
    <app:workspace xml:base="http://localhost:53644/">
        <a10:title type="text">Nicoloco Site</a10:title>
        <app:collection href="http://localhost:53644/api/blogapi">
            <a10:title type="text">Nicoloco Blog</a10:title>
            <app:accept>application/atom+xml;type=entry</app:accept>
            <app:categories href="http://localhost:53644/api/tags?format=atomcat" />
        </app:collection>
        <app:collection href="http://localhost:53644/api/images">
            <a10:title type="text">Images Blog</a10:title>
            <app:accept>image/png</app:accept>
            <app:accept>image/jpeg</app:accept>
            <app:accept>image/jpg</app:accept>
            <app:accept>image/gif</app:accept>
        </app:collection>
    </app:workspace>
</app:service>

But I can't publish images using this service.

Best regards.

È stato utile?

Soluzione

I found my error on "categories line", WLW log file shows a malformed XML error in this line, I removed it and all works fine for me... in this blog post explains how WLW Works with image files

If somebody have any comment... I'll be grateful

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top