views:

10

answers:

1

I have a project whereby I have a WCF service that I basically want invoked whenever a file is dropped in a certain directory. I've got the basic custom transport channel logic that I saw published on the web that deals with transport over a file. However, there's another point, the content of the file itself. The file is going to be a comma-delmited file of data. For each line in the file, I want a specific method to be invoked on the service. This is the part I am having trouble with.

I do understand that part of this will involve a custom MessageEncoder. Here's my back-of-the-napkin design. The encoder will receieve a stream of data (the file). It will read one line from the file and create a Message from it (that part I'm still a little clueless on). Then, the fact that the Stream has more data to read should tell the file transport channel to read another message from it.

Am I on the right track? The other question is how my encoder should handle buffered calls. I get in an ArraySegment by value, so the only thing I can think of is to modify the incoming array (I can't just manipulate the offset, it won't get back to the original caller).

Thoughts? I know this is a bit of a ramble.

A: 

You can't do all that work in the MessageEncoder, because WCF has a strong one-message-in/one-message-out bias at that stage. Basically, you're likely going to have to put both your channel and your custom encoder to work together.

What I'd likely do to keep it simple would be for the transport channel itself to pick up the file, open it and read one record at a time from it, then produce (through the encoder) one message at a time to satisfy one receive() call.

As for how to deal with buffering, that's usually a drag, but what those sizes passed to the encoder are for is basically to allow you to set a hard limit on the maximum size of any buffers allocated (so that you don't even try to process messages too big). That's not really a problem, directly, if you use the streaming interfaces, however.

tomasr
Yeah, my thought was actually that the MessageEncoder would accept the stream, read enough to cover one message (in this case, one line), and then the transport channel would notice the stream hasn't been fully read, and so re-invoke the encoder to get another message (repeat until done).
Rich
You might be able to do that, but seems a bit more complicated than needed to me :)
tomasr