图像的WCF REST服务在Azure上不起作用?

时间:2012-11-13 09:29:48

标签: wcf image rest azure stream

我有一个有效的WCF REST服务(.NET 4.0)用于向下传输图像。但是,当此服务发布到Azure网站(.NET 4.5)时,加载的图像会随机损坏。这不会发生在本地,甚至不会发生在域内。

在Azure上,它并不一致。有时它会加载,有时则不加载。你可以在这里看看腐败:

http://telproabrdev.azurewebsites.net/logo/vyrobce/get?id=4bced4ee-7162-45a3-a495-7764305e2d56&format=PNG

这是我的代码(基本上):

合同:

[OperationContract]
[WebGet(UriTemplate = "get?id={id}&format={format}", 
    RequestFormat = WebMessageFormat.Xml, 
    ResponseFormat = WebMessageFormat.Xml, 
    BodyStyle = WebMessageBodyStyle.Bare)]
Stream GetImage(String id, String format);

实现:

public Stream GetImage(String id, String format)
{
   // stuff, stuff, stuff

   using (Stream original = GetImageStream())
   {
       Stream result = CreateThumbnailStream(original, width, height);
       result.Seek(0, SeekOrigin.Begin);
       return result;
   }
} 

private Stream GetImageStream() 
{
    Bitmap copy = new Bitmap(Resource.SomePicture);
    Stream result = new MemoryStream();
    image.Save(result, ImageFormat.Png);
    return result;
}

private Stream CreateThumbnailStream(Image image, Int32 width, Int32 height)
{
    Image image = Image.FromStream(stream);
    Image result = new Bitmap(width, height, PixelFormat.Format32bppArgb);

    // shrinking routine skipped for brevity

    return result;
}

到目前为止,我已经尝试过了:

  1. 删除所有'使用' - >没有效果(但可能是内存泄漏)
  2. 将MemoryStream包装在BufferedStream中 - >都能跟得上
  3. 删除Seek() - >没有图像(如预期的那样)
  4. 我做错了什么?它适用于不同的项目(尽管不是Azure)。 .NET 4.0 vs 4.5兼容性是罪魁祸首吗?

0 个答案:

没有答案
相关问题