Deploying and Configuring a Custom Policy

To deploy and configure a custom policy, you must perform the following tasks:

  1. Compile the assembly containing the custom policy class, the custom policy filter class, the binding element class, and the binding element extension class, and then deploy this assembly.
  2. Add the custom policy to the DCS ServiceConfiguration database.
  3. Configure the DCS Management Services console.
  4. Configure DCS services that use the policy.
  5. Configure client applications that connect to services that use the policy.

The following sections describe each of these tasks in more detail.

You should compile the classes that comprise and support a custom policy into an assembly. If you sign the assembly, you can copy it to the Global Assembly Cache (GAC); otherwise, you must place the assembly in a location where the DCS Management Services Console, the DCS service, and the DCS client application can access it, as follows:

  • For the DCS Management Services Console, copy the assembly to the bin folder in the DCS installation folder. The default DCS installation folder is C:\Program Files\Microsoft CIS\DCS\V1.0.
  • For a DCS service, copy the assembly to the bin folder in the folder that you specified when you deployed the service.
  • For a client application, add the assembly as a reference. This will copy the assembly to the bin folder that holds the client application executable program. Alternatively, specify the location of the assembly in the <assemblyBinding> section of the client application configuration file. For more information, see Application Configuration Files.

You must add the definition of your custom policy to the dbo.PolicyDefinitions table in the ServiceConfiguration database. The PolicyDefinitions table contains the following columns.

Column

Description

PolicyId

The primary key for the table. This value is automatically generated when you add a new policy definition to the table.

PolicyExpression

The XML qualified name of the policy. For example, the XML qualified name of the DCS context policy is http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:contextPolicy.

Policy Description

A brief description of the policy. The DCS Management Services Console displays this string when an administrator configures the policy for a service or operation.

IsServicePolicy

A single bit that indicates whether this is a service-level policy (1) or an operation-level policy (0).


You can use Microsoft SQL Server Management Studio to add a policy to the PolicyDefinitions table, or you can start the osql command-line utility and run an SQL INSERT statement. The following example adds the samplePolicy service-level policy to the table. For more information about the samplePolicy, see Creating Classes that Implement and Support a Custom Policy.


                    INSERT INTO [ServiceConfiguration].[dbo].[PolicyDefinitions]([PolicyExpression], [PolicyDescription], [IsServicePolicy])
VALUES("http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:samplePolicy", "Sample Policy", 1)

                  

You must add a reference to the assembly that contains the custom policy class to the configuration file for the DCS Management Services console. This file is named dcsmanagementservices.mmc.config. The default location for this file is C:\Program Files\Microsoft CIS\DCS\V1.0\bin.

Add a policyType element to the list of policy types in the <cis.serviceModel> section of the file. The policyType element has two properties that are described in the following table.

Property

Description

Expression

The name of the property. This must match the value for the policy in the PolicyExpression column in the PolicyDefinitions table in the ServiceConfiguration database.

Type

This is the fully qualified type reference of the assembly that contains the policy class.


The following sample shows the <policyTypes> section of the dcsmanagementservices.mmc.config file. The policy type for the samplePolicy policy appears at the end of the section.


                    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <cis.serviceModel>

    <policyTypes>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:businessLogPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Application.Policy.BusinessLogPolicy, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:cachingPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Application.Policy.CachingPolicy, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:contextPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Application.Policy.ContextPolicy, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:encodingPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Application.Policy.EncodingPolicy, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:securityPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Application.Policy.SecurityPolicy, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:serviceBindingPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Policy.ServiceBindingPolicy, Microsoft.ConnectedIndustry.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:protectionPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Policy.ProtectionPolicy, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:identityPolicy" Type="Microsoft.ConnectedIndustry.ServiceModel.Policy.IdentityPolicy, Microsoft.ConnectedIndustry.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </policyTypes>
    <policyType Expression="http://schemas.Microsoft.com/ConnectedIndustry/ServiceModel/2008/05/Policy:samplePolicy" Type="DCS.Samples.SamplePolicy.SamplePolicy, SamplePolicy"/>
    </policyTypes>
  </cis.serviceModel>
  ...
</configuration>

                  

The next time you start the DCS Management Services Console, your custom policy will be available when you add policies to a service, as shown in the following figure.

Dd632009.9d652df4-a125-4cf9-aa18-05eead2bde83(en-us,MSDN.10).png

Configuring the SamplePolicy custom policy

The default binding configuration for a DCS service uses the Microsoft.ConnectedIndustry.ServiceModel.Application.Bindings.ExtendedHttpBinding binding. You configure a service that uses a custom policy by using a custom binding configuration. You reference the custom policy as a binding element in the custom binding. You can also include the binding elements provided with WCF and DCS. For more information about the DCS binding elements, see Building a Custom Binding with DCS Binding Elements.You must also add the binding element class to the <policyImporters> section of the configuration file, and add the binding element extension class to the <bindingElementExtensions> section.

The following example shows the configuration file for a service. The file is configured to use the SamplePolicy custom policy.


                    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  ...
  <cis.serviceModel>
    <serviceFactory>
      <httpBaseAddress dnsAlias="CCF2009SERVER"/>
      <defaultServiceConfiguration serviceBehavior="DCSBehavior">
        <defaultEndpoint behaviorConfiguration="enableTracing">
          <defaultSimplexBinding binding="customBinding" bindingConfiguration="customPolicyBinding"/>
          <defaultDuplexBinding binding="extendedHttpBinding" bindingConfiguration="duplex"/>
        </defaultEndpoint>
      </defaultServiceConfiguration>
    </serviceFactory>
    ...
  </cis.serviceModel>
  <system.serviceModel>
    ...
    <bindings>
      <extendedHttpBinding>
        <binding name="simplex"/>
        <binding name="duplex" isComposite="true" />
      </extendedHttpBinding>
      <basicHttpBinding>
        <binding name="discovery" useDefaultWebProxy="false" />
      </basicHttpBinding>
      <customBinding>
        <binding name="customPolicyBinding">
          <samplePolicy enable="true"/>
          <dcsCaching/>
          <dcsBusinessLog/>
          <dcsContext/>
          <dcsEncoding/>
          <dcsSecurity/>
          <dcsIdentity/>
          <httpTransport/>
        </binding>
      </customBinding>
    </bindings>
    <client>
      <metadata>
        <policyImporters>
          <extension type="Microsoft.ConnectedIndustry.ServiceModel.Application.Context.ContextBindingElement, Microsoft.ConnectedIndustry.ServiceModel.Application,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
          <extension type="DCS.Samples.SamplePolicy.SampleBindingElement, SamplePolicy"/>
        </policyImporters>
        <wsdlImporters>
        </wsdlImporters>
      </metadata>
    </client>
    <extensions>
      <bindingExtensions>
        <add name="extendedHttpBinding" type="Microsoft.ConnectedIndustry.ServiceModel.Application.Bindings.ExtendedHttpBindingCollectionElement, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </bindingExtensions>
      <bindingElementExtensions>
        <add name="dcsContext" type="Microsoft.ConnectedIndustry.ServiceModel.Application.Context.ContextExtensionElement, Microsoft.ConnectedIndustry.ServiceModel.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
        <add name="samplePolicy" type="DCS.Samples.SamplePolicy.SampleBindingElementExtension, SamplePolicy"/>
      </bindingElementExtensions>
      ...
    </extensions>
  </system.serviceModel>
  ...
</configuration>

                  

The application configuration file for a client application that connects to a service that implements a custom policy must include the binding element that supports the custom policy. The binding element must be in the <policyImporters> section of the configuration file.

The following example shows a configuration file for a client application that is configured to import the SamplePolicy custom policy.


                    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  ...
  <system.serviceModel>
    <client>
      <metadata>
        <policyImporters>
          <extension type="Microsoft.ConnectedIndustry.ServiceModel.Application.Context.ContextBindingElement, Microsoft.ConnectedIndustry.ServiceModel.Application,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"/>
          ...
          <extension type="DCS.Samples.SamplePolicy.SampleBindingElement, SamplePolicy"/>
        </policyImporters>
      </metadata>
    </client>
    ...
  </system.serviceModel>
  ...
</configuration>

                  
Show: