Using Configuration Files

You have already been exposed to the concept of using a configuration file in an application. Configuration files usually assist you in the form of App.config or Web.config files for WCF services. These are great tools to alter the behavior of programs without changing code. These runtime tools are extensively used in WCF. You can manage settings for WCF bindings, behaviors, services, and diagnostics without manually modifying the configuration files in a text editor. The executable used for this activity is SvcConfigEditor.exe. You can find it in the <Drive Name>:Program FilesMicrosoft SDKsWindowsv6.0Bin directory. The main features of this tool are as follows:

  • You can create new configuration files for services and clients using a wizard approach. This process will guide you to choose binding, behavior, contract, and diagnostic settings.

  • You can validate an existing configuration file against the standard System.Configuration schema.

  • You can modify and manage configuration settings for services, executables, COM+ services, and web-hosted services.

You'll now investigate how you can use SvcConfigEditor.exe to improve the QuickReturns Ltd. example.

Configuration Editor: SvcConfigEditor.exe

Open the App.config file of the WCFSimpleClient project (refer to Listing 6-6). You are attempting to utilize SvcConfigEditor.exe to modify the content and add a new binding to the client. Here are the steps:

  1. Navigate to <Drive Name>:Program FilesMicrosoft SDKsWindowsv6.0Bin, and open SvcConfigEditor.exe. You can also refer to the help file in the same directory.

  2. Select File Open Config File, navigate to the directory of the App.config file for the WCFSimpleClient application, and open the file. Your screen should be similar to Figure 6-5.

    Service Configuration Editor screen for the WCFSimpleClient App.config file

You can view and modify every element of the configuration file using this graphical user interface. You can simply select the element you want to modify and type in the new value. For this example, let's change the wsHTTPBinding setting of the client to basicHttpBinding. Therefore, select the Binding element, and change the value to basicHttpBinding for the TradeService endpoint. Save the settings using File Save. You also need to change the binding settings for the TradeServiceHost App.config file for the same endpoint information and change wsHttpBinding to basicHttpBinding. Otherwise, an error will occur because of a binding mismatch. Now open the new configuration file, and view the changes in Visual Studio 2005. You can clearly view the changes in Listing 6-7 performed by SvcConfigEditor.exe and compare it to Listing 6-6.

Example. WCTSimpleClient App.config File After the Service Configuration Editor Change
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint address=http://localhost:8000/TradeService
            binding="wsHttpBinding"
            bindingConfiguration=""
            contract="ExchangeService.ITradeService"
            name="TradeServiceConfiguration" />
      <endpoint address=http://localhost:8000/TradeMonitor
            binding="wsHttpBinding"
            contract="ExchangeService.ITradeMonitor"
            name="TradeMonitorConfiguration" />
    </client>
  </system.serviceModel>
</configuration>

The configuration file changes are quite trivial with WCF services (refer to Chapter 3 for more details). You will also utilize SvcConfigEditor.exe in the rest of the chapter to apply numerous configuration file changes to implement message logging, tracing, performance counters, and WMI providers. Now you'll concentrate on adding tracing and message logging capabilities to a WCF service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset