This blog has moved to http://mode13h.azurewebsites.net.
The custom transport channel has been configured in code only so far. In order to make it configurable via app/web.config, there are a few additions required. This post covers how to add those.
Click here to see all the posts in this series. All the code is now available on github here: https://github.com/dmetzgar/custom-transport-channel
Adding a configuration element is relatively simple. The file transport is easier to work with because it has no configuration options. Handling custom configuration is handled in a later post. Add a new file to the library project called FileTransportBindingConfigurationElement, this will hold two classes: the configuration element and the collection element. The collection element is just one line, so I prefer to just put it in the same class file an the configuration element.
Notice that this really doesn't do much except identify the FileTransportBinding as the BindingElementType.
The next step is to update the FileTransportBinding to read from a configuration section. To do this, we add another constructor that takes a string and reads the FileTransportBindingCollectionElement out of the configuration section.
Starting from the service side, add an app.config and put in the following serviceModel section.
The bindingExtensions collection is what allows WCF to load the custom binding element. Since there are no configuration options, the binding just needs a name and to be assigned to an endpoint. The address is specified on the endpoint so it no longer needs to be in the main method. That simplifies the code for Program.cs down to this:
On the client side, we have to add another constructor to the ReverseClient proxy that can read from config.
Then add an app.config to the client with the following.
The same bindingExtension is added here on the client side. We do have some timeouts we can configure that are universal. This simplifies the main method of the client down to this:
And that's it!
Awesome! It saved me a lot of time.
@Hennadiy - Great! I'm glad you found it useful.