Programming the Commerce Server 2007 catalog system: Creating the CatalogContext

      The objects in the catalog system can now be programmed in two modes. In the first mode the catalog server assembly is loaded in the callers appdomain (aka inproc mode). In the second mode the functionality of the catalog system is available remotely via the catalog web service. The programming model and the methods available in both the modes are the same. The only difference is in the way the CatalogContext object is created. The CatalogContext object is the root object in the catalog system. All other objects are obtained from the CatalogContext object.


1. The Inproc mode : You use this mode when you are running your code on the web server. The CatalogContext code is initialized by specifying the sitename. The following code sample shows how to create a CatalogContext in this mode. You need to add references to the Microsoft.Commerceserver.catalog, Microsoft.CommerceServer.CrossTierTypes and Microsoft.CommerceServer.Shared assemblies. The objects in the catalog system reside in the Microsoft.CommerceServer.Catalog and Microsoft.CommerceServer namespaces.


CatalogSiteAgent siteInfo = new CatalogSiteAgent();

siteInfo.SiteName = "StarterSite";

siteInfo.AuthorizationMode = AuthorizationMode.ThreadContext;

siteInfo.AuthorizationPolicyPath = @"E:\Inetpub\wwwroot\CatalogWebService\CatalogAuthorizationStore.xml";

siteInfo.IgnoreInventorySystem = false;

CacheConfiguration cacheConfiguration = new CacheConfiguration();

cacheConfiguration.CacheEnabled =true;

cacheConfiguration.SchemaCacheTimeout = new TimeSpan(0, 10, 0);

CatalogContext context = CatalogContext.Create(siteInfo, cacheConfiguration);

Use the CatalogSiteAgent class to specify the site name, the authorization information and the inventory usage option.

The AuthorizationMode enumeration has the following values

  • AuthorizationMode.NoAuthorization : Do not perform any authorization checks. This mode should be used on the runtime sites.
  • AuthorizationMode.ThreadContext : Before performing any operation ensure that the user is authorized to perform it. The identity of the user is obtained from the user's thread context. This mode should be used in Console applications.
  • AuthorizationMode.HttpContext : Before performing any operation ensure that the user is authorized to perform it. The identity of the user is obtained from the current Http context. This mode should be used in web applications where users update the catalog system.

The AuthorizationPolicyPath specifies the location of the authorization store. The authorization store is an Xml file which contains which information about the authorized users and the operations they can perform.

Commerce Server 2007 now adds an inventory integration with the catalog system.The inventory system now allows you to store the inventory information like (onhandquantities, status etc) for products and variants in the catalog system. You can use the IgnoreInventorySystem parameter to turn off inventory integration.If the inventory resource exists and IgnoreInventorySystem parameter is set to false no inventory operations or lookups will be performed by the catalog methods.

Use the CacheConfiguration object to specify the caching configuration. Note that caching is turned off by default and is enabled by setting the cacheConfiguration.CacheEnabled property.

If you are using the Microsoft.CommerceServer.Runtime BCL then you can specify the cache configuration and the inventory integration option in the web.config of your runtime site.

2. The WebService mode: The CatalogContext object can also be initialized in the webservice mode by passing in the url of the catalog webservice.

CatalogServiceAgent catalogServiceAgent = new CatalogServiceAgent(@"https://Servername/CatalogWebservice/CatalogWebservice.asmx");

CatalogContext context = CatalogContext.Create(catalogServiceAgent);

Use the CatalogServiceAgent class to specify the url of the catalog web service. The other overloads on this method allow you to specify the authentication methods and a credential prompter.

If you are wondering how to specify the authorization, caching and inventory option this is specified through the catalogWebService element in web.config. All the attributes and child elements are documented in the web.config itself.


Note: Even though the CatalogContext class has the CreateFromConnectionString method, it exists only for backward compatibility and is now deprecated.