MSDN Magazine Launch Issue - February 15, 2008 - (Page 49) Figure 6 Module Service Class public sealed class ResponseModificationModuleService : ModuleService { [ModuleServiceMethod] public ArrayList GetFilterRules() { ArrayList items = new ArrayList(); ResponseModificationSection section = (ResponseModificationSection)ManagementUnit.Configuration .GetSection(“responseModification”, typeof(ResponseModificationSection)); foreach (ResponseModificationRuleElement rule in section.Rules) { items.Add(GetPropertyBag(rule)); } return items; } } Modules, and an implementation of the Microsoft.Web.Management.Server.ModuleService class, which exposes the service methods to perform the required management tasks. My Mvolo.ResponseModificationUI.Server.dll assembly contains the ResponseModificationModuleProvider class that is responsible for registering the ResponseModificationModuleService service class in addition to the client ResponseModificationModule module class, as shown in Figure 5. The ResponseModificationModuleService class derives from the ConfigurationModuleProvider class, which provides built-in support for controlling IIS Manager feature delegation based on the delegation state of the underlying configuration section. All you have to do is supply the configuration section name, responseModification, and IIS Manager automatically toggles the delegation state of the feature based on whether the section is locked or unlocked for any particular configuration path. The Microsoft.Web.Management framework provides several other ModuleProvider base classes that support various other delegation scenarios for the IIS Manager tool. The GetModuleDefinition method returns the type of the IIS Manager module that will be instantiated on the client in order to register the required IIS Manager UI components such as the management page itself. Note that the type of the client-side ResponseModificationModule class is a string, not a Type object, because the server assembly may not reference the client assembly that will be loaded in IIS Manager on a remote client machine. This is one side effect of the fact that the client and server components may be running in different processes and cannot share custom types. The ResponseModificationModuleService class is responsible for implementing the management functionality and exposing the service methods that will be invoked by the management page in IIS Manager (see Figure 6). The GetFilterRules method is an example of several methods exposed by the service, which perform management tasks using the configuration system and possibly other resources that are local to the server. The service is always instantiated on the server, so it always acts on local resources and does not need to worry about accessing resources differently in the remote administration scenario. Note that I’m again using the Microsoft.Web.Administration API to access the responseModification configuration section, and am using the strongly typed ResponseModificationConfigurationSection wrapper created for the module to access the configuration. The ManagementUnit property is the central entry point to the local server, exposing a number of other objects that allow access to the configuration system and other server-centric management objects that have been created by the Microsoft.Web.Management framework to assist with server management tasks. As a best practice, service implementations should always use the management unit for local configuration management tasks instead of creating their own configuration systems. Methods like GetFilterRules can return information to the client by using basic types such as ArrayList to relay information to the client components. Again, you cannot communicate using strongly typed classes defined in the server or client assemblies because they are intended to be separate and should not have references to each other. ResponseModificationModuleService also defines additional service methods similar to GetFilterRules, including EditFilterRule, AddFilterRule, and DeleteFilterRule, to support the required management operations that may be requested by the Response Modification module page. Creating the Module Page The client components define the actual GUI management functionality provided to the user by the IIS Manager tool. The client assembly typically contains the implementation of the following classes: • The Microsoft.Web.Management.Client.Module class, which is responsible for registering any required IIS Manager pages and other UI extensions. • The Microsoft.Web.Management.Client.ModulePage class, which describes the actual management page displayed by IIS Manager. Figure 7 Module Class public sealed class ResponseModificationModule : Module { protected override void Initialize(IServiceProvider serviceProvider, ModuleInfo moduleInfo) { base.Initialize(serviceProvider, moduleInfo); IControlPanel controlPanel = (IControlPanel)GetService(typeof(IControlPanel)); controlPanel.RegisterPage( new ModulePageInfo(this, typeof(ResponseModificationModulePage), Resources.PageTitle, Resources.PageDescription, null, null, Resources.PageText )); } } IIS 7.0 launch2008 49
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.