Share via


How to Create a CatalogContext Object

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

The CatalogContext object provides the functionality to manage your catalogs. It can be created in one of two modes. It can be in local mode, where the code accesses the Commerce Server objects and the database directly and does not use a Web service.

Alternatively, it can be in agent mode, where calls to the catalog system are made through the Web service with the help of an agent.

For more information about the programming modes, see Understanding the Different Types of Commerce Server APIs.

For best performance, do not create multiple CatalogContext objects. Instead, create a single instance and reuse it for the lifetime of the application.

To create a CatalogContext object in local mode

  1. Create a CatalogSiteAgent object. This object contains the configuration information that is required to connect to the catalog database.

  2. Create a CatalogContext object. This object contains the methods that you need to manage your catalogs.

To create a CatalogContext object in agent mode

  1. Create a CatalogServiceAgent object. This object contains the authentication information that is required to communicate with a Web service.

  2. Create a CatalogContext object.

Example

This example creates two CatalogContext objects. The first method uses a CatalogSiteAgent object to create the CatalogContext object in local mode. The second method uses a CatalogServiceAgent object to create the CatalogContext object in agent mode. It uses a parameter url, which is the URL of the Web service against which the agent will run.

public static CatalogContext CreateCatalogContextFromSiteAgent()
{   
    // Create a CatalogSiteAgent to connect to the database.
    CatalogSiteAgent catalogSiteAgent = new CatalogSiteAgent();
    catalogSiteAgent.SiteName = "StarterSite";

    // Create the CatalogContext object.
    CatalogContext catalogContext = CatalogContext.Create(catalogSiteAgent);
    return catalogContext;
}

public static CatalogContext CreateCatalogContextFromServiceAgent(string url)
{
    // Create a CatalogServiceAgent to connect to the Web service.
    CatalogServiceAgent serviceAgent = new CatalogServiceAgent(url, new string[] {"ntlm", "kerberos", negotiate"});
    // Create the CatalogContext object.
    CatalogContext catalogContext = CatalogContext.Create(serviceAgent);

    return catalogContext;
}

See Also

Other Resources

Before You Start Developing with the Catalog System