2013-05-20 34 views
0

我想用ASP.NET WEB API创建一个Atompub服务,一切都可以,但是当我尝试从Windows Live Writer发布任何图像时,出现错误“The blog doesn不允许图片加载“我正在阅读ietf doc允许在AtomPub ASPNET Web Api服务器中的图像

我的服务控制器代码:

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> 

但我不能发布使用这项服务的图像。

此致敬礼。

回答

1

我发现我的错误的“类行”,WLW日志文件显示了这一行业的畸形XML错误,我删除它和所有工作正常,我...在this博客文章解释WLW如何与图像文件

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

相关问题