2011-04-10 19 views
1

我目前正在开发使用Windows窗体应用程序从Windows计算机收集一些数据的Windows客户端。我需要将这些数据发送到服务器。但我不知道最好的办法是什么。我目前正在尝试WCF Web服务来获取数据并返回true或false。但我需要学习发送数据到服务器的最快方式。客户必须可靠和快速。我的选择或最佳方式是做什么的。服务器仅将数据发回为true或false。最好的方式发布数据客户端到服务器C#

回答

1

的我会在RhinoServiceBus看一看。这是快速和相当容易实施。如果你不喜欢,那么我也会使用WCF。

+0

我认为_RhinoServiceBus_需要_MSMQ_,我无法使用_msi installer_安装_MSMQ_。你知道一个正确的方法来做到这一点或运行_RhinoServiceBus_运行没有_MSMQ_ – 2011-04-11 07:14:01

+0

这解决了我的问题。谢谢。 – 2011-04-11 19:56:30

2

如果我有这样的任务,我也会使用WCF web服务。

唯一的一个区别我会做:在错误的情况下void类型和抛出异常。

1

您可以使用基于TCP或UDP等套接字的低级网络传输协议,但您必须自己管理转换和序列化。

在C#中你可以使用的TcpClient和的TcpListener类,(在这个例子中的BinaryFormatter)以某种序列化的序列化你的对象

ServerCode:

... 
TcpListener listener = new TcpListener(8080); 
listener.Start(); 
using (TcpClient client = listener.AcceptTcpClient()) 
{ 
    BinaryFormatter formatter = new BinaryFormatter(); 
    //Assuming the client is sending an integer 
    int arg = (int)formatter.Deserialize(client.GetStream()); 
    ... //Do something with arg 
    formatter.Serialize(result); //result is your boolean answer 
} 
... 

ClientCode:

... 
    using (TcpClient client = new TcpClient(ipaddress, 8080) //ipaddress is the ip address of the server 
    { 
    BinaryFormatter formatter = new BinaryFormatter(); 
    formatter.Serialize(client.GetStream(), 12) //12 is an example for the integer 
    bool result = formatter.Deserialize(client.GetStream()); 
    ... //do something with result 
    } 
    ... 

但是,正如你所看到的,最快(UDP可能更快,但不能保证发送数据)的方式并不是最简单的(并不总是最好的)。

因此,对于一个Windows窗体项目,我会用一些“现成的” RMI/RPC API像WCF或ASP.Net Web服务

+0

我必须知道数据发送和参与工作完成。我不希望任何数据松动。 – 2011-04-10 13:55:13

+0

UDP不保证传送。 TCP增加了这个功能。 – 2011-04-10 16:41:54

相关问题