林試圖從WCF服務的圖片
我有一個返回的圖片給客戶端,
但是當我從客戶 調用它,我得到這個異常的OperationContract的功能: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9619978'.
返回圖像(WCF服務)
客戶:
private void btnNew_Click(object sender, EventArgs e)
{
picBox.Picture = client.GetScreenShot();
}
Service.cs:
public Image GetScreenShot()
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bmp = new Bitmap(bounds.Width,bounds.Height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
using (MemoryStream ms = new MemoryStream())
{
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return Image.FromStream(ms);
}
}
}
IScreenShot接口:
[ServiceContract]
public interface IScreenShot
{
[OperationContract]
System.Drawing.Image GetScreenShot();
}
所以這是爲什麼發生,如何解決呢?
你可能想看看WCF [大數據和流(http://msdn.microsoft.com/en-us/library/ms733742.aspx)。 –
@JoshuaDrake我以前讀過它,但我無法理解這一切,我只理解,如果我想傳輸大量數據,我應該使用流化代替緩衝。但是,它,我改變緩衝流,然後我得到了圖像? –
你可以嘗試將圖像格式更改爲jpg而不是png。有時流png有問題。 – Rajesh