我有一个有效的WCF REST服务(.NET 4.0)用于向下传输图像。但是,当此服务发布到Azure网站(.NET 4.5)时,加载的图像会随机损坏。这不会发生在本地,甚至不会发生在域内。
在Azure上,它并不一致。有时它会加载,有时则不加载。你可以在这里看看腐败:
这是我的代码(基本上):
合同:
[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;
}
到目前为止,我已经尝试过了:
我做错了什么?它适用于不同的项目(尽管不是Azure)。 .NET 4.0 vs 4.5兼容性是罪魁祸首吗?