WMI Support in WCF

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

 

2 Comments

  • Hi Pablo,

    I've followed the exact steps you've exposed and when I go to WMI Object Browser I don't have any AppDomaInfo instances and no output from the powershell script neither.

    Any idea?

    Phil

  • You must have the service running i.e. the end point must be in listening mode. You can easily do that by running the WCF service in visual studio in debug mode, which launches WCFSvcHost to host the service and WCF Test Client to connect to that service. Then WMI tool to connect to it.

Comments have been disabled for this content.