CatalogServiceAgent Constructor (Uri, String[])

Initializes a new instance of the CatalogServiceAgent class for communicating with a specific Web service using the provided type of Web service proxy object.

Namespace:  Microsoft.CommerceServer.Catalog
Assembly:  Microsoft.CommerceServer.Catalog (in Microsoft.CommerceServer.Catalog.dll)

Syntax

'Declaration
Public Sub New ( _
    uri As Uri, _
    supportedAuthMethods As String() _
)
'Usage
Dim uri As Uri
Dim supportedAuthMethods As String()

Dim instance As New CatalogServiceAgent(uri, supportedAuthMethods)
public CatalogServiceAgent(
    Uri uri,
    string[] supportedAuthMethods
)
public:
CatalogServiceAgent(
    Uri^ uri, 
    array<String^>^ supportedAuthMethods
)
public function CatalogServiceAgent(
    uri : Uri, 
    supportedAuthMethods : String[]
)

Parameters

  • uri
    Type: System..::.Uri
    The URL of the Web service this agent will run against.
  • supportedAuthMethods
    Type: array<System..::.String>[]()[]
    A list of authorization modes which are allowed.

Remarks

The ServiceAgent will not prompt on authentication failure.

The Catalog Agent serves to abstract data from the user interface. Additionally, it caches frequently changing data and batch-processes user interface queries.

Examples

public CatalogContext GetCatalogContext()
{
  CatalogContext catalogContext = null;
  CatalogServiceAgent catalogServiceAgent = null;

  try
  {
    if (config.InitializationMode == ConnectionMode.Agent)
    {//AGENT MODE
      if ((config.UserName == null) || (config.UserName.Equals(
        Environment.GetEnvironmentVariable("USERDOMAIN") + @"\" +
          Environment.GetEnvironmentVariable("USERNAME"))))
      {
        // Default case when nothing is specified
        // Uses the user's default credentials when anonymous is not allowed
        catalogServiceAgent = new CatalogServiceAgent(config.WebServiceURL, ServiceAgent.DefaultAuthMethods);

        catalogContext = CatalogContext.Create(catalogServiceAgent);
      }
      else if (config.UserName != null)
      {
        // Create custom
        CredentialCache credentials = new CredentialCache();
        NetworkCredential networkCredential = new NetworkCredential();
        //create new uri with web service url
        System.Uri uri = new System.Uri(config.WebServiceURL);
        //add the user name, password, and domain to the network credential
        int index = config.UserName.IndexOf(@"\");
        networkCredential.UserName = config.UserName.Substring(index + 1);
        networkCredential.Password = config.Password;
        networkCredential.Domain = config.UserName.Substring(1, index - 1);

        //add the network credential to the credential cache collection
        credentials.Add(uri, "NTLM", networkCredential);

        catalogServiceAgent = new CatalogServiceAgent(config.WebServiceURL, ServiceAgent.DefaultAuthMethods);
        catalogServiceAgent.Credentials = credentials;

        catalogContext = CatalogContext.Create(catalogServiceAgent);
      }
      else
        throw new System.InvalidOperationException("Cannot perform this operation without initialization");
    }
    else
    {//INPROC MODE
      CatalogSiteAgent csa = new CatalogSiteAgent();
      csa.AuthorizationMode = config.AuthorizationMode;
      csa.AuthorizationPolicyPath = config.AzManXmlFileStore;
      csa.IgnoreInventorySystem = config.IgnoreInventorySystem;
      csa.SiteName = config.SiteName;
      catalogContext = CatalogContext.Create(csa);
    }
  }
  catch (Exception e)
  {
    Console.WriteLine("Error getting CatalogContext: " + e.Message);
    throw e;
  }
  if (catalogContext != null)
    inventoryContext = catalogContext.InventoryContext;
  return catalogContext;
}

Permissions

See Also

Reference

CatalogServiceAgent Class

CatalogServiceAgent Members

CatalogServiceAgent Overload

Microsoft.CommerceServer.Catalog Namespace