我正在尝试设置一个将返回图像的WCF服务,在测试过程中这是我正在使用的,并且它始终有效。
FileStream fs = File.OpenRead(@"C:\pic.jpg");
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
return fs;
现在最后一步是返回一个生成的图像,只是一个简单的框,什么都没有。尝试了多次迭代并运气相同,ERR_CONNECTION_RESET始终存在错误。
//trying to use this, but it causes in ERR_CONNECTION_RESET
using (FileStream stream = new FileStream("image.jpg", FileMode.Create))
{
Bitmap bmp = new Bitmap(300, 300);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.Transparent);
g.FillRectangle(Brushes.Red, 100, 100, 100, 100);
g.Flush();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
stream.Position = 0;
return stream;
}
当我比较fs和stream时,我看到的唯一真正区别是他们分别有2560和2564的差异。
这是服务合同
[ServiceContract]
public interface IEmailService
{
[OperationContract]
[WebGet(UriTemplate = "GetImage/{token}/{guid}", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
Stream GetImage(string token, string guid);
}
由于