0
我正在嘗試使用wcf和net.tcp綁定將位圖從客戶端傳遞到服務器。如何使用WCF和net.tcp綁定來傳輸位圖?
這是我的代碼到目前爲止...請建議什麼是最好的方式來使它流的位圖?
public void ScreenShot()
{
...
System.Drawing.Bitmap gdiBitmap = new System.Drawing.Bitmap(pictureBox1.Image);
apc.server.return_screenshot(name, gdiBitmap);
///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.9700000'.
}
...
[ServiceContract(Namespace = "server",
CallbackContract = typeof(IfaceServer2Client),
SessionMode = SessionMode.Required)]
public interface IfaceClient2Server ///// what comes from the client to the server.
{
[OperationContract(IsOneWay = true)]
void StartConnection(string clientName);
[OperationContract(IsOneWay = true)]
void Message_Cleint2Server(string msg);
[OperationContract(IsOneWay = true)]
void ret_listDrives(string n, List<TreeNode> nodeList);
[OperationContract(IsOneWay = true)]
void return_screenshot(string n, Bitmap img); /// <- here I'm trying to pass the bitmap.
}
public interface IfaceServer2Client ///// what goes from the sertver, to the client.
{
[OperationContract(IsOneWay = true)]
void AcceptConnection();
[OperationContract(IsOneWay = true)]
void RejectConnection();
[OperationContract(IsOneWay = true)]
void Message_Server2Client(string msg);
[OperationContract(IsOneWay = true)]
void cmd_listDrives();
[OperationContract(IsOneWay = true)]
void cmd_changeName(string n);
[OperationContract(IsOneWay = true)]
void cmd_screenshot();
}
謝謝!
編輯:
private void Form1_Load(object sender, EventArgs e)
{
duplex = new ServiceHost(typeof(ServerClass));
NetTcpBinding tcp = new NetTcpBinding();
duplex.AddServiceEndpoint(typeof(IfaceClient2Server), tcp, "net.tcp://localhost:9080/service");
duplex.Open();
}
我對這個東西有點新...可以請您詳細解釋一下嗎? :) – Roger 2011-04-16 15:51:00
在這裏你去... – DarkSquirrel42 2011-04-16 18:11:57
謝謝!嗯......但它仍然顯示相同的錯誤,當我試圖傳遞字節[] bmpBytes ... ///套接字連接被中止。 ///這可能是由於處理您的消息時發生錯誤或遠程主機接收超時,或者底層網絡資源問題導致的。本地套接字超時爲'00:00:59.9950000'。 – Roger 2011-04-18 14:46:31