How to configure your WCF service to work as norma

2019-05-21 03:36发布

问题:

How can I configure my WCF service to work as a normal TCP server? Is it possible to disable all that binding specific stuff so as to keep your service URL like http://example.com:4444/service and be able to work vith pure HTTP/TCP streams?

I need to be able to work with TCP streams in tandem with WCF services... so I have to make TCP server from one of my WCF services or (and I do not know how) make my self-hosted WCF services work in pair with my stand alone TCP server. However, I just can not find how to make them share the same port so as to be able to call http://example.com:4444/WCFservice/ http://example.com:4444/TCPserver/ (And I have to make them share it; taking 2 ports is not an option.)

回答1:

The easiest way to add TCP endpoint to the service is modify you web.config file with respect of "WCF Service configuration editor". You can find it in the "Tools" menu of Visual Studio of in context menu of web.config (also in VS). You need add new endpoint with netTcpBinding. The address of such new endpoint will be start with "net.tcp://". For more information you can read http://msdn.microsoft.com/en-us/library/cc949080.aspx.

For net.tcp port sharing read http://msdn.microsoft.com/en-us/library/aa395195.aspx or google for: wcf tcp endpoint port sharing.

A good review of new features of WCF 4 you can find in http://msdn.microsoft.com/en-us/library/ee354381.aspx

And take it easy if somebody don't understand advantages of WCF compares with Winsocket programming. 15 year ago I used sockets and find it cool. Then I used RPC, DCOM etc. Now WCF is the best way if you think about authentication of your endpoint. So take some of previous comments easy.



回答2:

If you want to work with pure TCP streams you'd probably work with sockets directly and not WCF.

Use WCF when you want things auto implemented for you at the transport layer.