DCSIMG
Using UDP multicast channel in WCF - Dotmad (on .Net)

Dotmad (on .Net)

Just Another Web 5.0 Blog

Podcasts

Blogroll

Using UDP multicast channel in WCF

I recently needed to build a WCF UDP application as a proof of concept.

Sadly UDP is not among the channels bundled with the WCF, so I needed to put up something myself:

  • Downloaded the WCF technology samples, containing a UDP transport demo (there used to be a sample at the netfx3 site, but it's long-gone) 
  • Copied the UDP transport sample project (from the folder \Extensibility\Transport\Udp\Cs\UdpTransport) into my solution
  • Added the extensions section to the config file to add the UDP support (config file coming up soon)
  • Added multicast="true" switch to the binding section
  • The address prefix is hardcoded in the UdpChannelHelpers.cs file, so if you like something other than "soap.udp" you need to edit the "Scheme" constant.
  • Since UDP is limited by a 64kb packet size, you may also want to use the GZipEncoder (found in \Extensibility\MessageEncoder\Compression\CS\GZipEncoder)

You need to remember that since this is multicast, the client is the one doing the transmitting while the service is a only a passive listener.

Client configuration:

<configuration>
    <system.serviceModel>

      <extensions>
        <bindingElementExtensions>
          <add name="udpTransport" type="Microsoft.ServiceModel.Samples.UdpTransportElement, UdpTransport" />
        </bindingElementExtensions>
        <bindingExtensions>
          <add name="sampleProfileUdpBinding" type="Microsoft.ServiceModel.Samples.SampleProfileUdpBindingCollectionElement, UdpTransport" />
        </bindingExtensions>
      </extensions>

      <client>
        <endpoint address="net.udp://225.225.0.1:2222/Observer/"
          binding="customBinding"
          bindingConfiguration="DatagramServer" contract="MyNamespace.IObserver"
          name="ClientService" />
      </client>

      <bindings>
        <customBinding>
          <binding name="DatagramServer">
            <binaryMessageEncoding></binaryMessageEncoding>
            <udpTransport multicast="true" />
          </binding>
        </customBinding>
      </bindings>

    </system.serviceModel>
</configuration>

 

Service configuration:

<configuration>
    <system.serviceModel>

      <extensions>
        <bindingElementExtensions>
          <add name="udpTransport" type="Microsoft.ServiceModel.Samples.UdpTransportElement, UdpTransport" />
        </bindingElementExtensions>
        <bindingExtensions>
          <add name="sampleProfileUdpBinding" type="Microsoft.ServiceModel.Samples.SampleProfileUdpBindingCollectionElement, UdpTransport" />
        </bindingExtensions>
      </extensions>
   
      <services>
            <service name="ObserverService.Observer">
              <endpoint address="net.udp://225.225.0.1:2222/Observer/"
                  binding="customBinding"
                  bindingConfiguration="DatagramServer"
                  contract="MyNamespace.IObserver" />
            </service>
       </services>
      <bindings>
        <customBinding>
          <binding name="DatagramServer">
            <binaryMessageEncoding></binaryMessageEncoding>
            <udpTransport multicast="true" />
          </binding>
        </customBinding>
      </bindings>
    </system.serviceModel>
 
</configuration>

פורסם: Jun 10 2008, 02:59 PM by Dotmad | with 1 comment(s)
תגים:,

תוכן התגובה

Dotmad (on .Net) כתב/ה:

After creating a custom UDP mulitcast channel using WCF I ran some tests. I used this sample data contract

# June 11, 2008 10:57 AM