Defining Scopes
When you deploy a DCS service and define a service instance, you can specify a list of scopes that the service instance will respond to. A scope is a structured string identifier associated with the service instance. When a client connects to a service through the DCS Discovery Service, it must provide two pieces of information: the service contract and the scope of the service instance to connect to. The service contract specifies the functionality of the service to connect to, and the scope helps match the client to the most appropriate service instance. For more information, see DCS Scopes.
To define and apply a scope to a service you must perform the following tasks:
- Add the scope to the Discovery database. You can add new scopes to the Discovery database either by manually editing the dbo.Scopes table in the Discovery database, or programmatically by using the CreateScope operation of the DiscoveryAdminService service.
- Configure the service to use the scope. You use the DCS Management Services Console to associate a scope with a service endpoint.
You must add the definition of your custom scope to the dbo.Scopes table in the Discovery database. The Scopes table contains the columns described in the following table.
|
Column |
Description |
|---|---|
|
ID |
The primary key of the table. This value is automatically generated when you add a new policy definition to the table. |
|
Scope |
The colon-delimited string representation of the scope to store in the database. |
You can use Microsoft SQL Server Management Studio to add a scope to the Scopes table, or you can start the osql command line utility and run an SQL INSERT statement. The following example adds the sample Contoso.Banking.BranchOperations scope to the table.
INSERT INTO [Discovery].[dbo].[Scopes]([Scope])
VALUES('Contoso:Banking:BranchOperations')
DCS lets you create a new scope in the Discovery database programmatically by invoking the operations on the DiscoveryAdminService. You can create a client application to invoke this service to add scopes to the database. This application can be a useful tool to enable administrators to update the scope database for maintenance.
When you create the client application, create a WCF Service Reference to the DiscoveryAdminService.svc endpoint. This creates a WCF proxy object that you can use to invoke the required operations. When you add a service reference to the application, Visual Studio generates an application configuration file, which should resemble the following example.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="ExtendedHttpBinding_IDiscoveryAdminService"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows"
proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows"
negotiateServiceCredential="true"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://ccf2009server/ManagementServices/DiscoveryAdminService.svc"
binding="wsHttpBinding"
bindingConfiguration="ExtendedHttpBinding_IDiscoveryAdminService"
contract="DASReference.IDiscoveryAdminService"
name="ExtendedHttpBinding_IDiscoveryAdminService"
/>
</client>
</system.serviceModel>
</configuration>
After you add the service reference, create an instance of the DiscoveryAdminServiceClient object, which you will use to invoke operations.
To create a new scope, you can use one of two methods defined in the DiscoveryAdminServiceClient class:
- CreateScopeByScopeName – This method accepts a single string parameter that contains the scope to add to the database. The following code example creates the Contoso:Banking:BranchOperations scope by using this method.
-
DASClient.CreateScopeByScopeName("Contoso:Banking:BranchOperations"); - CreateScope.– This method accepts a Proxy.Scope() object (where Proxy is the scope name). First, create a Scope object, and then modify the Scope.ScopeName to contain the scope name that you want to add. You then pass the scope object as a parameter to the CreateScope method call. The following code example creates the Contoso:Banking:CustomerOperations scope by using the CreateScope method.
-
DASReference.Scope newScope = new DASReference.Scope(); newScope.ScopeName = "Contoso:Banking:CustomerOperations"; DASClient.CreateScope(newScope);
Note: |
|---|
| The CreateScopeByName method calls the CreateScope method internally. You cannot create multiple instances of the same scope name in the Discovery database. If you attempt to add a scope that already exists, the method call returns without creating a new instance of the scope. |
The following code sample shows a complete client application that calls the CreateScopeByScopeName and CreateScope methods, and then prints a list of all scopes declared in the Discovery database.
using DCSScopeManagement.DASReference;
namespace DCSScopeManagement
{
class ScopeManager
{
static void Main(string[] args)
{
DiscoveryAdminServiceClient DASClient = new DiscoveryAdminServiceClient();
// Create a scope by using the CreateScopeByScopeName method.
DASClient.CreateScopeByScopeName("Contoso:Banking:BranchOperations");
// Create a scope by using the CreateScope method.
DASReference.Scope newScope = new DASReference.Scope();
newScope.ScopeName = "Contoso:Banking:CustomerOperations";
DASClient.CreateScope(newScope);
// Print a list of declared scopes.
foreach (DASReference.Scope scope in DASClient.GetAllScopes())
{
Console.WriteLine(scope.ScopeName);
}
Console.ReadKey();
}
}
}
Note: