tags:

views:

19

answers:

2

I want to create a framework , which should be configurable through App.config. just like our WCF Host

To make it clear

I need to only write the 3 line to host the service with the below configuration

Type serviceType = typeof(DerivativesCalculatorServiceType);
ServiceHost host = new ServiceHost(serviceType))
host.Open();

WCF configuration

<configuration>
   <system.serviceModel>
      <services>
         <service name="DerivativesCalculator.DerivativesCalculatorServiceType" 
                  behaviorConfiguration="DerivativesCalculatorService">

            <endpoint  address="Calculator"  
                       binding="basicHttpBinding" 
                       contract="DerivativesCalculator.IDerivativesCalculator"/>
         </service>
      </services>
      <behaviors>
         <serviceBehaviors>
             <behavior name="DerivativesCalculatorService">
                 <serviceMetadata httpGetEnabled="true" />
             </behavior>
         </serviceBehaviors>
      </behaviors>
   </system.serviceModel>
</configuration>

I want to know how is the binding object, endpoint object, Contract created internally by parsing the xml, because xml is strings, how is the corresponding objects or class created internally.

For example AddServiceEndpoint

AddServiceEndpoint(typeof(IDerivativesCalculator), basicHttpBindingObject, Address);

how is DerivativesCalculator.IDerivativesCalculator from converted to IDerivativesCalculator

A: 

You could use the System.Configuration classes to access the App.config and read in configuration values. Here is a decent article to get you started.

DrDeth
A: 

DerivativesCalculator.IDerivativesCalculator in the XML specifies the name of the interface that defines the contract. IDerivativesCalculator is the actual interface, that is defined in the Derivatives namespace.

Reflection is used to find a type in the assembly. The Assembly.GetType(String) method is an example of a reflection method. This method can be used to return the IDerivativesCalculator type, by passing the DerivativesCalculator.IDerivativesCalculator name to the method.

Reflection can also be used to create instances of a type, again based on just the name of the type. This is how you can populate an object based on a configuration file.

Niels van der Rest