简体   繁体   English

如何在同一个套接字上托管WCF服务和TCP服务器?

[英]How to host WCF service and TCP server on same socket?

Tooday I use ServiceHost for self hosting WCF cervices. Tooday我使用ServiceHost来托管WCF服务。

I want to host near to my WCF services my own TCP programm for direct sockets operations (like lien to some sort of broadcasting TCP stream) 我想在我的WCF服务附近托管我自己的TCP程序,用于直接套接字操作(比如某种广播TCP流的留置权)

I need control over URL namespaces (so I would be able to let my clients to send TCP streams directly into my service using some nice URLs like example.com:port/myserver/stream?id=1 or example.com:port/myserver/stream?id=anything and so that I will not be bothered with Idea of 1 client for 1 socket at one time moment, I realy want to keep my WCF services on the same port as my own server or what it is so to be able to call www.example.com:port/myWCF/stream?id=222... and I want it to work on Any port - not only 80) 我需要控制URL名称空间(所以我可以让我的客户端使用一些不错的URL直接将TCP流发送到我的服务中,例如example.com:port/myserver/stream?id=1或example.com:port/myserver / stream?id =任何东西,所以我不会在1个socket的1个客户端的想法中受到困扰,我真的希望将我的WCF服务保留在与我自己的服务器相同的端口上,或者它是什么样的能够打电话给www.example.com:port/myWCF/stream?id=222 ...我希望它可以在任何端口上工作 - 不仅仅是80)

Can any body please help me with this? 任何人都可以帮我这个吗?

I am using just WCF now. 我现在只使用WCF。 And I do not enjoy how it works. 我不喜欢它是如何工作的。 That is one of many resons why I want to start migration to clear TCP=) 这是为什么我要开始迁移以清除TCP =)的众多原因之一

I can not use net-tcp binding or any sort of other cool WS-* binding (tooday I use the simpliest one so that my clients like Flash, AJAX, etc connect to me with ease). 我不能使用net-tcp绑定或任何其他酷WS- *绑定(今天我使用最简单的绑定,以便我的客户像Flash,AJAX等轻松连接到我)。

I needed Fast and easy in implemrnting connection protocol like one I created fore use with Sockets for real time hi ammount of data transfering. 我需要快速简单地实现连接协议,就像我在套接字中创建的那样,实时用于数据传输。

So.. Any Ideas? 那么......有什么想法? Please - I need help. 请 - 我需要帮助。

Well if you're going to drop down to pure sockets, you could as well make your service act as proxy. 好吧,如果你要下降到纯插槽,你也可以让你的服务充当代理。 Make WCF Services listen on some other port, and your app on the desired port. 使WCF服务侦听其他端口,并在所需端口上侦听您的应用程序。 When you receive request in your app, manually parse header and check weather it is intended for your service or WCF Service. 当您在应用程序中收到请求时,请手动解析标题并检查天气是否适用于您的服务或WCF服务。 If it's intended for WCF service, open a TCP connection to WCF service and pass the received data to it, and then simply pass back WCF's answer to the client.. 如果它用于WCF服务,打开到WCF服务的TCP连接并将接收到的数据传递给它,然后简单地将WCF的答案传回客户端。

On the other hand you could speed up WCF quite a lot by writing your own custom binding. 另一方面,通过编写自己的自定义绑定,可以大大加快WCF的速度。 Lots of time WCF looses on serialization that is done using reflection (which is slow), going around this would improve your speed considerably. 很多时候WCF在使用反射(这很慢)完成的序列化时会失败,绕过这会大大提高你的速度。

If your problem with WCF is performance then you should try the binary net TCP binding to eliminate XML serialization to improve performance. 如果您的WCF问题是性能,那么您应该尝试使用二进制网络TCP绑定来消除XML序列化以提高性能。

Some high traffic applications, like realtime games, use UDP for the majority of communication since it cuts through the protocol. 一些高流量应用程序(如实时游戏)使用UDP进行大部分通信,因为它会切断协议。 With TCP you get ordering and reliability built in, but this comes at the cost of performance because it will implicitly delay packets to wait for out of order packets so that it can hand them to the application in the correct order, or wait for lost packets to be resent. 使用TCP,您可以获得内置的排序和可靠性,但这会以性能为代价,因为它会隐式延迟数据包以等待乱序数据包,以便它能够以正确的顺序将它们交给应用程序,或等待丢失的数据包被重新发送。 Instead you can use UDP and implement your own scheme for verification of data that is less stringent than TCP. 相反,您可以使用UDP并实现自己的方案来验证不如TCP严格的数据。

There are UDP options available for WCF, or you could implement your own. 有可用于WCF的UDP选项,或者您可以实现自己的。 WCF is nothing more than a message pump, and you can replace different steps with whatever you want. WCF只不过是一个消息泵,你可以用你想要的任何东西替换不同的步骤。

不确定这是否会对您有所帮助,但请尝试启用Net TCP共享服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM