Pablo M. Cibraro (aka Cibrax)

My thoughts on Web Services and .NET development

News

Pablo Cibraro's VisualCV

Blogs

Personal

Programming

Client Configuration in WCF 4.0

As Dr Nick announced in this post, WCF 4.0 will ship with a new feature to configure a client channel from a configuration source other than the traditional section in the application configuration file (I discussed a workaround for doing the same thing in WCF 3.0 a time ago in this post)

This will provide the flexibility to deploy some binaries with the client proxies together with an independent configuration file (which might be a resource file, a stand alone file included with your application or something you can download from an specific place), so the main configuration file does not need to be touched at all.

A new channel factory “ConfigurationChannelFactory” is included as part of the System.ServiceModel.Configuration namespace to create channels from an alternative configuration source.

var fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = "otherFile.config";

var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

var factory = new ConfigurationChannelFactory<IService1>("BasicHttpBinding_IService1", configuration, new EndpointAddress("http://localhost:49187/Service1.svc"));

var client = factory.CreateChannel();

var s = client.GetData(3);

Console.WriteLine(s);

The file “otherFile.config” is just a simple configuration file that contains the client definition and configuration for using the “IService1” service.

<configuration>
 
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
              <binding name="BasicHttpBinding_IService1" >
                    <security mode="None">
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:49187/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration>

All this code is based on the .NET 4.0 beta 1, so it might change in the final release.

Posted: Sep 08 2009, 11:14 AM by cibrax | with 2 comment(s)
Filed under: ,

Comments

Sam Gentile's Blog (if (DeveloperTask == Communication && OS == Windows) said:

SOA/Indigo/WCF/Oslo SOA Patterns - Reservations Client Configuration in WCF 4.0 Some History of the Named Pipe, Part 4 - The last part in this series is to bring the history of the named pipe up to the named pipe implementation in WCF. WOW ! *The* guy

# September 8, 2009 6:20 PM

Twitter Trackbacks for Client Configuration in WCF 4.0 - Pablo M. Cibraro (aka Cibrax) [asp.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Client Configuration in WCF 4.0 - Pablo M. Cibraro (aka Cibrax)         [asp.net]        on Topsy.com

# September 9, 2009 1:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)