Question

I have both ends of a bi-directional connected Stream, which I want to do some communication over. The underlying implementation behind the stream isn't important, I want to work at the Stream level...

Rather than implement my own communications protocol for the stream, I want to use all of the existing WCF goodness to wrap the existing stream with with a bi-directional (request/response + callback) WCF communications channel.

My question is, how can I go about doing this...?

UPDATE:

I've gone down the path of implementing a custom transport. I've got this working, but I'm still not totally happy with it...

I've implemented an IDuplexSessionChannel to wrap the stream, along with appropriate IChannelFactory and IChannelListener, and a Binding Element for creating the channel factories. Now, I just pass through the connected stream, and eventually pass these into the transport channel when it is created.

So, I can create the client proxy for accessing the service via the stream as follows:

var callback = new MyCallback();
var instanceContext = new InstanceContext( callback );
var pipeFactory = new DuplexChannelFactory<IMyService>( instanceContext, new StreamBinding(clientStream),
                                                        new EndpointAddress("stream://localhost/MyService"));
var serviceProxy = pipeFactory.CreateChannel();

The problem I have is, it seems WCF is set on using a ServiceHost to create the server end of the channel, via a IChannelListener. In my case, I already have a connected stream, and I won't be able to listen for any more incoming connections. I can work around this, but I'd much rather not use a ServiceHost to create the server end of the channel, because I end up with a lot of obscure boilerplate and hacks to make it work.

Questions

I'm looking, therefore, for a better way to take the IDuplexSessionChannels, and wrap these into a Channel proxy at both the server and client ends.

Or maybe a different ServiceHost implementation that doesn't require a IChannelListener.

Really, the problem here is I don't want a single server, multiple client arrangement, I have a 1-1 relationship between my WCF Service and the client. Is there a correct way to instantiate one of these?

To put it yet another way, I want to create the Server-side service instance without using a ServiceHost.

Any suggestions would be appreciated at this stage.

Was it helpful?

Solution

Use a client at both ends. You will need to define your contracts carefully though. If you have ClientA and ClientB at either end of the stream, when ClientA sends a request, ClientB will expect it to look like what it sees as it's defined callback contract and vice versa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top