简体   繁体   中英

How to create a WCF that listens to TCP requests over web

I have a gps device that will send packets to TCP connection hosted over web that will have a static IP address & dedicated port for it.

My question is how to achieve it using WCF ? Or if WCF is needed or not for this problem.

Please help me. Thanx in advance.

Did you mean TCP embedded transported/embedded using http? or just TCP but using the internet?

The last is supported for sure.


To set a TCP connectionover WCF is easy, just use NetTcpBinding, you can set this in C# code or better in .config file like this:

<system.serviceModel>
  <bindings>
    <netTcpBinding name="portSharingBinding" 
                   portSharingEnabled="true" />
  </bindings>
  <services>
    <service name="MyService">
        <endpoint address="net.tcp://localhost/MyService"
                  binding="netTcpBinding"
                  contract="IMyService"
                  bindingConfiguration="portSharingBinding" />
    </service>
  </services>
</system.serviceModel>

There's no differece between setup a TCP channel in a private network or in a public one (internet)

I strongly recommend You to read a A truely simple example to get started with TCP and WCF

Depending the type of data being sent you could use (in ascending order of abstraction):

Examples of use are given in the documentation.

TCP Listener : https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener(v=vs.110).aspx

HttpListner : https://msdn.microsoft.com/en-us/library/system.net.httplistener(v=vs.110).aspx A nice example here: https://www.codehosting.net/blog/BlogEngine/post/Simple-C-Web-Server.aspx

Or use a full framework like WebApi or Nancy .

http://www.asp.net/web-api

http://nancyfx.org/

Without knowing how you are wanting to send the data it is hard to recommend but don't reinvent the wheel if you don't have to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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