Surprisingly this is not supported by default in the release version of Silverlight 2 due to the absence of the required configuration-related classes needed to expose the Polling Duplex binding and binding element to the WCF configuration system. However, thanks to the great extensibility model of WCF it is possible to enable this scenario and bridge the gap by registering a custom binding extension.

The aim is to render the StockServiceHost class (defined in code above) redundant and instead replace it’s functionality entirely in a configuration file, in this case App.config. As you can see in the InitializeRuntime method the StockServiceHost class actually registers two endpoints: in addition to the PollingDuplexHttpBinding endpoint there is the WebHttpBinding endpoint to account for the Silverlight 2 cross-domain policy requirements. It would defeat the aim to succeed in defining one of these endpoints in the configuration file without the other, so the measure of success is to be able to define both in App.config. How this aim can be achieved is shown below:

Notice under the <bindingExtensions> element that the pollingDuplexHttpBinding item relies on the following two configuration-related classes (demonstrated in use as part of the sample application or available separately for download above) in the PollingDuplexConfig.cs file:

To configure Polling Duplex in Silverlight 2 solely via the .config file the PollingDuplexHttpBindingCollectionElement class including the relevant namespace and assembly, need to be referenced in the type attribute of the pollingDuplexHttpBinding item under the <bindingExtensions> element as shown in the configuration markup above.

As this is a standard way to create and register a custom binding extension, once the configuration classes and markup are in place as shown and the project successfully builds, you can edit the binding in the same way as the built-in WCF bindings by opening the produced .config file (StockServer.exe.config in this case) in SvcConfigEditor.exe while the service is running: