Posts Tagged ‘ WCF 4.5 ’

UDP Broadcast using BizTalk Server 2010

Recently we had talked about developing an adapter to broadcast data over UDP.  The idea was to develop such an adapter that can be used in private equity firms to receive price data over multicast.

Yesterday I had a chance to try out Dot Net 4.5 (currently in beta) which natively supports UDPBindings.  I never realized broadcasting data over UDP would be such a simple task that I could implemented a send port in a matter of minutes with 0 coding. Well 0 coding to set the port up but may be a few lines of code for the UDP receiver.

Setting up a UDP Send port

In your BizTalk application, create a send port of WCF-Custom Type.  In the General tab, set the End Point Address URI to be

soap.udp://<multicast_address>:<port>

Image

On the Binding Tab, Select the Binding Type to be “udpBinding”.  Leave the defaults as is

Image

Set the other required files and maps on your port and that’s it.  You can now broadcast messages over UDP.

Client Code

Here is the client code that I used to test my UDP Transmission.

            const int GROUP_PORT = 15000;
            //const string IP_ADDRESS = "192.168.56.1";
            const string IP_ADDRESS = "192.168.0.110";
            Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(IP_ADDRESS), GROUP_PORT);
            listener.Bind(localEndPoint);
            EndPoint ep = (EndPoint)localEndPoint;
            Console.WriteLine("Ready to receive…");
            byte[] data = new byte[1024];
            int recv = listener.ReceiveFrom(data, ref ep);
            string stringData = Encoding.ASCII.GetString(data, 0, recv);
            Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
            Console.ReadLine();
            listener.Close();

Its a pure socket based connection and works like a charm.

In my BizTalk application, my UDP Broadcast port was subscribing to a file receive port.  For both ports the pipeline was simple pass through.  I dropped in a simple xml file with data:

<?xml version="1.0" encoding="utf-8"?>
<data>WORKING PARTY</data>

And this is what I received on my client console application:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:MessageID>urn:uuid:9552802b-0168-431f-b694-eff5fed86a47</a:MessageID><a:To s:mustUnderstand="1">soap.udp://192.168.0.110:15000/</a:To></s:Header><s:Body><data>WORKING PARTY</data></s:Body></s:Envelope>
Advertisements