0

我正在尝试使用 ASP.NET WEB API 创建 Atompub 服务,一切都很好,但是当我尝试从 Windows Live Writer 发布任何图像时,我收到一个错误“博客不允许加载图像”我正在阅读IETF文档。

我的服务控制器代码:

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;
    }
}

http GET 请求生成以下 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>

但我无法使用此服务发布图像。

此致。

4

1 回答 1

1

我在“类别行”上发现了我的错误,WLW 日志文件在这一行中显示了格式错误的 XML 错误,我删除了它并且一切正常……在这篇博文中解释了 WLW 如何处理图像文件

如果有人有任何意见...我将不胜感激

于 2013-05-22T15:36:28.057 回答