July 2007 - Posts

The configSource attribute was firstly introduced in .NET framework 2.0 to support external configuration files.

This attribute can be added to any configuration section to specify a an external file for that section. Using an external configuration source can be useful in many scenarios. For instance, you could place a section into an external configSource if you need an easy method to swap settings for the section depending on the environment (development, test, or production), or  you need granular control over permissions.

Unfortunately, the system.serviceModel section group does not support this attribute. If you try to add it, you will receive the following exception:

The attribute 'configSource' cannot be specified because its name starts with the reserved prefix 'config' or 'lock'

What I found out is that you can use this attribute on the different sections under system.serviceModel such as services, behaviors or bindings.

For instance, the configuration file could look like this,

<configuration>

 

  <system.serviceModel>

    <services configSource="Services.config" >

    </services>

 

    <bindings configSource="Bindings.config">

    </bindings>

 

    <behaviors configSource="Behaviors.config">

    </behaviors>

 

  </system.serviceModel>

 

</configuration>

 And then, each file contains the corresponding section.

Services.config

<services>

  <service name="Microsoft.ServiceModel.Samples.CalculatorService"

          behaviorConfiguration="CalculatorServiceBehavior">

    <host>

      <baseAddresses>

        <add baseAddress="http://localhost:8000/servicemodelsamples/service"/>

      </baseAddresses>

    </host>

    <!-- this endpoint is exposed at: net.tcp://localhost:9000/servicemodelsamples/service  -->

    <endpoint address="net.tcp://localhost:9000/servicemodelsamples/service"

              binding="netTcpBinding"

              bindingConfiguration="Binding1"

              contract="Microsoft.ServiceModel.Samples.ICalculator" />

    <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->

    <endpoint address="mex"

              binding="mexHttpBinding"

              contract="IMetadataExchange" />

  </service>

</services>

Bindings.config

<bindings>

  <netTcpBinding>

    <binding name="Binding1"

            closeTimeout="00:01:00"

            openTimeout="00:01:00"

            receiveTimeout="00:10:00"

            sendTimeout="00:01:00"

            transactionFlow="false"

            transferMode="Buffered"

            transactionProtocol="OleTransactions"

            hostNameComparisonMode="StrongWildcard"

            listenBacklog="10"

            maxBufferPoolSize="524288"

            maxBufferSize="65536"

            maxConnections="10"

            maxReceivedMessageSize="65536">

      <readerQuotas maxDepth="32"

                    maxStringContentLength="8192"

                    maxArrayLength="16384"

                    maxBytesPerRead="4096"

                    maxNameTableCharCount="16384" />

      <reliableSession ordered="true"

                      inactivityTimeout="00:10:00"

                      enabled="false" />

      <security mode="Transport">

        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />

      </security>

    </binding>

  </netTcpBinding>

</bindings>

Behaviors.config

<behaviors>

  <serviceBehaviors>

    <behavior name="CalculatorServiceBehavior">

      <serviceMetadata httpGetEnabled="true" />

      <serviceDebug includeExceptionDetailInFaults="False" />

    </behavior>

  </serviceBehaviors>

</behaviors>

Posted by cibrax | 8 comment(s)
Filed under: ,

If you haven't taken a look yet, Microsoft SharedView is a fast and easy way to share documents and screen views with small groups of friends or coworkers; anytime, anywhere, and what is most important, it is completely free. This version is available up to 15 people in different locations.

Although it is still in beta version, I have been using this product for a while to show the progress of my work to other off-site teams, and it works pretty well with a standard internet connection.

If you want to try it, it is available here.

A nice thing about the management layer in WCF is the WMI support to expose instrumentation at runtime with a well-know interface. That instrumentation includes different service characteristics such as contracts, services, behaviors, listeners or application hosts, which can be accessed by different management tools.

The built-in provider can be activated in the configuration file of the application through the "wmiProviderEnabled" attribute in the diagnostics element, as it is shown below,

<system.serviceModel>

    <diagnostics wmiProviderEnabled="true">

 

      <messageLogging logEntireMessage="false" logMalformedMessages="false" logMessagesAtTransportLevel="false" logMessagesAtServiceLevel="false"/>

    </diagnostics>

    ...........

</system.serviceModel>

Of course, this can be also be done through the SvcConfigEditor tool, which is the way I usually use for simplicity.

Once the WMI provider is enabled, and the service host is running, we will able to use a tool like WMI Object Browser to see the published information.

As is shown in the image above, if we browse to the objects in the namespace "root\ServiceModel", we will able to see an AppDomainInfo object with information about the WCF settings, and the service endpoints as well.

Also we can change some of those settings at runtime (These changes will not be saved in the configuration), for instance, to enable message logging, which can be ideal to detect sporadic problems on a specific server.

Other settings like Performance counters can also be enabled through this WMI model, but it requires some programming since it can not easily done with tools like this one.

And finally, Powershell scripts can also be used to query information about the objects published by the built-in WMI provider.

PS C:\Users\pci> get-wmiobject -class "AppDomainInfo" -namespace "root\servicemodel" -computername "."

__GENUS : 2
__CLASS : AppDomainInfo
__SUPERCLASS :
__DYNASTY : AppDomainInfo
__RELPATH : AppDomainInfo.AppDomainId=2,Name="b576ed9b-1-128279485591533267",ProcessId=2184
__PROPERTY_COUNT : 12
__DERIVATION : {}
__SERVER : PCI-MOBILE
__NAMESPACE : root\servicemodel
__PATH : \\PCI-MOBILE\root\servicemodel:AppDomainInfo.AppDomainId=2,Name="b576ed9b-1-128279485591
533267",ProcessId=2184
AppDomainId : 2
IsDefault : False
LogMalformedMessages : False
LogMessagesAtServiceLevel : False
LogMessagesAtTransportLevel : False
MessageLoggingTraceListeners :
Name : b576ed9b-1-128279485591533267
PerformanceCounters : Off
ProcessId : 2184
ServiceConfigPath : C:\Projects\Service WMI\service\web.config
ServiceModelTraceListeners : {xml}
TraceLevel : Information

 

Posted by cibrax | 4 comment(s)
Filed under: ,
More Posts