tags:

views:

242

answers:

2

I have several "blackbox" that sends data to determinated IP and PORT, I can´t specify anything else (just IP and PORT)...

My server should be listening that PORT and catch information to send to MSMQ...

How can I set a WCF server to listening that PORT?

Thanks!

+3  A: 

I would write a normal windows service that listens for the data.

Use the TCPListener or a similar class

Then plug on WCF as a seperate service that your windows service calls to write to the message queue, it's just a matter of configuration.

[ServiceContract]
public interface IDaraWriterService
{
     [OperationContract]
     public void WriteDataToQueue(WriteDataToQueueMessage theDataEncapsulatedInAMessage)
     {
     }
}

Your windows service could probably write to the queue directly btw.

See here for more info on the message queue. http://msdn.microsoft.com/en-us/library/ms811053.aspx

Rob Stevenson-Leggett
Thanks... In that Windows service I need to set up a socket to listen that port, right?
Paul
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx
Rob Stevenson-Leggett
Thanks...What you think using ThreadPool to process the clients? Is it a good choice?
Paul
+2  A: 

If you can control what's pushing data to the IP address/port, then yes, you could use WCF. Unfortunately, without some sort of contract/binding to specify the means by which your "server" and your "client" communicate, WCF won't help you much.

So if you can't control the client code, you'll need to "roll your own" listener. As @Rob Stevenson-Leggett suggested: TcpListener

Edit:

Thanks Randolpho... So, I´ll develope a Windows Service with the listener and add the message to MSMQ. And in the otner hand, I need a module to read the queue (MSMQ) and add that to DB... That module could be in WCF? What you think?

Yep. WCF provides the MsmqIntegrationBinding for communicating on either end with an MSMQ.

Here's a nice tutorial:

http://msdn.microsoft.com/en-us/library/ms789008.aspx

Randolpho
Thanks! I´m thinking in use a ThreadPool to process the clients... What you think?
Paul
Definitely. Pass processing of each opening on the port to a threadpool. Be very careful, however -- you're opening yourself up to concurrency issues.
Randolpho
Thanks Randolpho...So, I´ll develope a Windows Service with the listener and add the message to MSMQ.And in the otner hand, I need a module to read the queue (MSMQ) and add that to DB... That module could be in WCF? What you think?
Paul
I think between us we've got a design here. Windows Service listening on the port and writing to it with a WCF service watching the MSMQ.
Rob Stevenson-Leggett
Good! Thanks again...I will implement all that now!!!
Paul
Just one last question...What about if I dont use MSMQ ? Is it really necessary?If I receive the data(tcp) and put directly on DB Instead of adding in MSMQ?Thanks!
Paul