套接字比。 WCF [英] Sockets Vs. WCF

查看:178
本文介绍了套接字比。 WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在一个聊天式的应用程序,在这里我使用Silverlight在客户端和WPF在服务器端。现在的通信是基于套接字:我有不同的消息类我序列化和发送通过TCP

我开始意识到,建立一个单独的邮件类各不可能性通信场景是相当的开销,并考虑迁移到WCF。

因此​​,我需要知道以下几点:

  1. 看来,使用WCF整个通信是基于客户callind露从我的WCF服务的方法。有没有知道哪个客户端调用某个方法的一种方式?这是我的应用程序非常重要。

  2. 请问WCF通知我的应用程序,当客户端断开连接(如关闭其中的Silverlight客户端运行的浏览器窗口)从服务器?这也是非常重要的。

  3. 是方法调用完全异步?如果是这样,我必须重新路由每个方法调用服务器应用程序的主线程?

  4. 是否每个客户端连接都有自己的线程?多少个并发连接可以在服务器(一个合理的动力的PC上运行)处理,如果客户端调用的方法说每2秒?我只是需要一个估计(10,100,1000,甚至更多)。 更多将是巨大的;)

也许我是完全错误和WCF不起作用基于连接的。然后,我必须找到一个解决办法仍然管理活动连接的列表。

感谢您的帮助! 安德烈

解决方案
  1. 由于您使用的Silverlight应用程序,你可以实现一个UserNamePassword验证的消息层,它增加了一些头到SOAP消息,这可能是用来唯一标识客户,除非客户是匿名的。那么你可以使用System.ServiceModel.OperationContext.Current,当你需要在其他地方获得的用户名在WCF服务。

  2. 服务器未收到通知时,客户端disconnets,因为封邮件是PerCall在默认情况下,有一种方法,使用单例类作为乌拉圭回合的ServiceContract与InstanceContextMode.Single,然后实现了回调服务的OperationContract的,那么当客户登录到乌尔服务,他们必须与回调服务注册,则UR回调服务可以循环连接的客户端,并检查回调的状态,其是否仍处于打开状态还是不行,最后取出其中连接关闭项,最终你可以得到你所需要的功能。

  3. 异步调用,是由客户端,IE浏览器。在Silverlight中所有的web服务电话是异步,像在ASP中你有一个选择,WCF自动处理异步功能,所以你不需要重新路由什么,只是code像它的一个线程的ServiceContract,一切都会好起来的

  4. 执行二进制消息编码在Silverlight 3中,以获得最大的乌尔服务器和带宽,Silverlight不支持原始的TCP连接,它有一个http消息被敲击有很好的理由。每个客户端可以有多个并发呼叫(异步记不清了),所以让事情变得简单,只是把它当作如果服务器分配一个单独的线程每一个消息调用。因此,要回答你刚才说的,1000你的问题。

I work on a chat-like application, where I use Silverlight on the client side and wpf on the server side. Right now the communication is based on Sockets: I have different Message-Classes which I serialize and send via TCP.

I start realizing that creating a seperate Message Class for each possibile communication scenario is quite an overhead and consider moving to WCF.

Therefore I need to know the following things:

  1. It seems that the whole communication using WCF is based on the clients callind exposed methods from my WCF service. Is there a way of knowing which client calls a certain method? This is quite important for my application.

  2. Does WCF notify my application, when a client disconnects (e.g. closes the browser window where the Silverlight client is running) from the server? This too is quite important.

  3. Are the method calls completely asynchronous? If so, do I have to reroute each method call to the main thread of the server application?

  4. Does every client connection has its own thread? How many simultaneous connections could the server (running on a reasonably powered PC) handle if the clients call methods say every 2 seconds? I just need a estimation (10, 100, 1000 or even more). "More" would be great ;)

Maybe I am completely wrong and WCF doesn't work connection-based at all. Then I would have to find a workaround to still manage a list of active connections.

Thanks for your help! Andrej

解决方案

  1. Since you are using a Silverlight application, you can implement a UserNamePassword Validator on the message layer, which adds some headers to the soap message, this could be used to uniquely identify clients, unless clients are anonymous. then you can use System.ServiceModel.OperationContext.Current, when you need to access the username elsewhere in the wcf service.

  2. The server is not notified when the client disconnets, since msgs are "PerCall" by default, there is a way, use a Singleton class as ur ServiceContract with InstanceContextMode.Single, then implement an OperationContract with a callback service, then when clients login to ur service they must register with the callback service, ur callback service can then cycle through connected clients and check the status of the callback, whether its still open or not, finally remove entries where the connections are closed, eventually you can get the functionality you require.

  3. Async calls, are from the client, ie. in Silverlight all webservice calls are async, like in ASP you have a choice, WCF handles the async functionality automatically, so you dont need to reroute anything, just code the ServiceContract like its a single thread, and everything will be fine

  4. Implement binary message encoding in silverlight 3, to get the most out of ur server and its bandwidth, silverlight does not support raw tcp connections, it has to be rapped in an http message for very good reasons. Each client can have many concurrent calls (async remember), so to keep things simple, just think of it as if the server assigns a separate thread to every message call. So to answer your question on what you just said, 1000.

这篇关于套接字比。 WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆