2
votes

Normally a WCF TCP channel will make a connect to a host then allow you to make method calls over it.

I would like to have a service which makes outbound connections to the clients, but once the connection has been made then clients would be able to make method calls against my service as if it were a conventional connection.

I suspect that this is some kind of a custom channel but wondered if a) this had already been done b) whether there were any pitfalls I should try and avoid

Note - that I'm not talking about a duplex style callback, but rather the client and server going on to have a conventional style conversation where the server responds to client requests through the standard wcf dispatcher - only the originator of the underlying tcp connection is the server rather than the client.

Siz suggests it is as simple as using a duplex contract. To expand the requirements slightly: a) The client is prohibited from making connections to the server. So if the duplex channel makes a seperate tcp connection then this won't work. I think from my tests that it doesn't but shares the originating the connection under tcp (can anyone confirm?)

b) There are multiple services on the server that the client needs to call so the "Callback contract" mechanism of setting up the reverse connection will be awkward as there will need to be many "register" style calls to get them all set up. Ideally I would like to set up multiple services all at once - is this possible using this approach?

1

1 Answers

3
votes

Take a look at MSDN here. NetTcpBinding supports duplex communication.

In your case, mapping to WCF terms, all the clients would actually be hosting a service and the host would actually be a client connecting to multiple hosts. A duplex channel will allow you to send messages both ways.

Duplex communication does not mean callback functions, but an entire contract. When a client opens a duplex connection to a host, it ends up running its own server listening to incoming calls from the server along the callback contract handle. Any message sent client -> server or server -> client will go through all the standard WCF infrastructure.

It is fair to say that this doesn't exactly answer your question. However, for create any channel you will need the connection initiator to contact some kind of server first. So the easiest way to do this would be the duplex connection.