WCF - Multiple Channel Implementation

Hey,

I have a service endpoint on an MSMQ which is receiving messages from multiple clients, would there be a way for me configure my receive service in such a way as to have a single channel accept messages from a single client? Would appreciate any help you can give in terms of configuring WCF or custom implementation on top of WCF.

The message is sent to the MSMQ from the client by way of the "Chunking Channel" binding.

Thanks

[508 byte] By [Kapoochikaya] at [2008-1-9]
# 1
I'm reading a bit into this, so correct me where I mess up. It sounds like you

want to take a set of messages that arrive in the queue and correlate them. To do correlation on one-way messages in MSMQ, just use sessions on the channel. Then, all your one-way messages will show up in a single entry in the queue and will be read one after the other, so it'll look like a session to the reader and writer. If this isn't write, then please expand on what you want to do so that we can give you better advice.

ScottSeely at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2
Well there are multiple clients involved; the messages being sent from the clients are chunked up into chunks and sent over the network, then re assembled at the server side to make the message. When the clients transmit concurrently the chunks are being interleaved. In order to avoid this I want to be able to make sure that chunks from each client would be accepted by separate channels.
Kapoochikaya at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3

One solution that will work is to create a separate endpoint/client. This isn't a bad idea if the number of clients is constrained.

If the number isn't constrained or is too large to make sense, you can insert a header into each message identifying the 'session' by making the Chunking channel emit a System.Xml.UniqueId identifying the session. Then, you can change the chunking channel to reassemble the messages based on UniqueId. When all the messages for a given UniqueId are pulled from the queue, you can notify the channel up the stream.

ScottSeely at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4

Hey Scott,

Thanks for the prompt replies, well the number is not constrained and can be quite large. The method you have mentioned is how I am progressing at present. The enhancement I was hoping to make was to implement it such that, there would be an instance of the channel for each client sending chunks (session), and the Channel.Receive method would return only chunks from that client. Does that make sense?

Kapoochikaya at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5

This makes sense. There are a number of ways to solve this problem, depending on the rest of the architecture you have in place.

Maybe you can explain why you have chosen to use the chunking channel example with MSMQ instead of using a streamed channel.

ScottSeely at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 6

Well I needed a reliable messaging delivery system in place; I would need to transfer fairly big files through the system so I would need to chunk into manageable chunks as MSMQ has a 4mb maximum message size.

Kapoochikaya at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 7

It seems like you need to set the InstanceContextMode to PerSession. A new service object is created for each client session. I am not sure what binding you are using but it would need to support sessions.

This link has more details about instancing and sessions

http://msdn2.microsoft.com/en-us/library/ms731193.aspx

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)] public class MyService : IMyService { … } 
jyotsnav at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 8

I am using a custom binding with the MSMQTransport which does not support sessions I believe, how would I go about building that capability in?

Kapoochikaya at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 9

Hey, the following is the custom binding I am currently using, how could I go about extending this to use sessions?

<customBinding>

<binding name="chunkingBindingElement">

<chunkingBindingElementExtension />

<msmqTransport durable="true" maxReceivedMessageSize="204800">

<msmqTransportSecurity msmqAuthenticationMode="None" msmqProtectionLevel="None" />

</msmqTransport>

</binding>

</customBinding>

I tried putting <reliableSession ordered="true" /> but the following error pops in whatever position I set it.

Binding 'CustomBinding' doesn't support creating any channel types. This often indicates that the BindingElements in a CustomBinding have been stacked incorrectly or in the wrong order. A Transport is required at the bottom of the stack. The recommended order for BindingElements is: TransactionFlow, ReliableSession, Security, CompositeDuplex, OneWay, StreamSecurity, MessageEncoding, Transport.

I also tried the use of session-grams but it looks like that would not be suitable as the files I would need to send across are going to be greater than 4 Mb.

Kapoochikaya at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 10

MSMQ is not a persistent store if that is why you are choosing it, MSMQ removes the message from the queue once its consumed.

If you need reliable messaging (i.e. need to ensure the messages get delivered, in order, etc) then you want to use a binding with Reliable Messaging enabled, but don't need MSMQ.

As far as THIS binding goes, its missing an encoder.

DavidKreutz-MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified