Configuring a DCS Service to Use a Custom Context Class

You configure a DCS service to use a custom Context class by using the custom <context> section of the service configuration file. You must include the Microsoft.ConnectedIndustry.ServiceModel.Common.ContextSection configuration class to enable the <context> section.

You must also specify how to serialize instances of this class. Add the <dataContractSerializer> element to the <system.runtime.serialization> section of the service configuration file and specify that the class should be serialized by using the data contract for the Microsoft.ConnectedIndustry.ServiceModel.Common.Context object. For more information about configuring serialization, see <system.runtime.serialization>.

The following code shows the elements of a service configuration file that configures the service to use a custom Context class named DCS.Samples.ExContextSample. For more information about the ExContextSample custom context class, see Implementing a Custom Context Class.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="context" type="Microsoft.ConnectedIndustry.ServiceModel.Common.ContextSection,Microsoft.ConnectedIndustry.ServiceModel.Common,Version=1.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
  ...
  </configSections>
  ...
  <context>
    <extension type="DCS.Samples.ExContextSample, DCSExtensionMessages"/>
  </context>
  ...
  <system.runtime.serialization>
    <dataContractSerializer>
      <declaredTypes>
        <add type="Microsoft.ConnectedIndustry.ServiceModel.Common.Context, Microsoft.ConnectedIndustry.ServiceModel.Common">
          <knownType type="DCS.Samples.ExContextSample, DCSExtensionMessages"/>
        </add>
      </declaredTypes>
    </dataContractSerializer>
  </system.runtime.serialization>
</configuration>

Specifying a Custom Context Property in a Service Scope

A DCS service can also specify a custom context property as an element in the scope for a service. For example, a DCS client application can create an instance of the ExSampleCustomContext class and populate the ExProperty property with a value such as DemoExPropertyValue. A custom scope provider that is designed to handle custom context objects that include this property can construct a scope that includes the value of this property and then pass this scope to the Discovery Service to locate all service instances that respond to this scope. For more information about custom scope providers, see Building a Custom Scope Provider and Ranker.

The following example adds a scope that includes the DemoExPropertyValue custom property value in a scope to the dbo.Scopes table in the Discovery database.

INSERT INTO [Discovery].[dbo].[Scopes] ([Scope]) VALUES ('DEMO:DemoExPropertyValue')

You can then use the DCS Management Services Console to add this scope to the list of scopes that a service responds to, as shown in following figure.

Dd632251.7138cb6d-2c97-42bc-9bc4-a4258518e020(en-us,MSDN.10).png

Defining a scope that references a custom context property value

For more information about creating new scope definitions, see DCS Scopes.

Note

Because of a known limitation, custom context properties cannot be used in task filters.

See Also

<system.runtime.serialization>

Implementing a Custom Context Class

Building a Custom Scope Provider and Ranker

Defining Scopes