Technical · Web Services

Multicast with WCF 3.5

December 5, 2010

Web Services

Multicast with WCF 3.5

For Distributed Architecture scenarios with Multicast using WCF 3.5 one possible option is the following:

[ServiceContract(Namespace = "http://servicios.cliente/2009/06", Name = "IRouter")]
public interface IServiceRouter
{
   [OperationContract(ReplyAction = "*", Action = "*")]
   Message ForwardMessage(Message message);
}

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
class ServiceRouter : IServiceRouter
{

        #region IRouter Members

        public Message ForwardMessage(Message message)
        {
            Message BogotaServer;
            Message localServer;

            MessageBuffer messageBuffer = message.CreateBufferedCopy(int.MaxValue);
            Message messageCopy = messageBuffer.CreateMessage();
            Message messageCopy2 = messageBuffer.CreateMessage();

            //Almacenamiento en servidor local finca   
            int headerLocalIndex = message.Headers.FindHeader("Key", "http://serviciosproduccionCP");
            if (headerLocalIndex != -1)
            {
                string localHost = message.Headers.GetHeader<string>(headerLocalIndex);
                ChannelFactory<IServiceRouter> client = new ChannelFactory<IServiceRouter>(localHost);
                localServer = (client.CreateChannel()).ForwardMessage(messageCopy);
            }
            else
            {
                throw new InvalidOperationException("No se puede encontrar la cabecera 'local'");
            }

            //Almacenamiento en servidor de Bogotá.  
            int headerBogotaIndex = message.Headers.FindHeader("Key", "http://serviciosproduccionBogota");
            if (headerBogotaIndex != -1)
            {
                string bogotaHost = message.Headers.GetHeader<string>(headerBogotaIndex);
                ChannelFactory<IServiceRouter> client = new ChannelFactory<IServiceRouter>(bogotaHost);
                BogotaServer = (client.CreateChannel()).ForwardMessage(messageCopy2);
            }
            else
            {
                throw new InvalidOperationException("No se puede encontrar la cabecera 'bogota'");
            }

            return BogotaServer; 

        }

        #endregion
    }


This code analyzes the information sent by the client and creates a copy of the message, which is later distributed to the servers that are registered in the message header. This routing technique is based on Content — the content of the SOAP message header.

 

Juan Peláez

3Metas Corp.

Need Expert Help?

Let's discuss how I can help with your technical challenges

Schedule a Consultation

Get the next one in your inbox

More like this, once a week. The Digest covers AI systems and agents in one weekly edition.

Confirm by email to complete your subscription. Unsubscribe anytime.

Related reading

More in the Digest — a weekly roundup of AI and agents news — or start with AI Strategy. Want help with this? Tell me about your needs →