IBM FileNet P8, Version 5.2.1            


< Previous | Next >

Adding Connection Code

After you rename the default C# source file, you add code that uses the Content Engine .NET API to connect to Content Platform Engine.

Renaming the C# Source File

When you created the project, Microsoft Visual Studio generated a C# source file, Program.cs, by default. Rename this file to better reflect its purpose.
  1. In the Solution Explorer pane, right-click Program.cs and click Rename.
  2. Type over the existing name. For example, P8Connector.cs.
  3. In the prompt for renaming all project references to this file, click Yes.

Coding the Connection

  1. If the C# source file is not already open, double-click its name in the Solution Explorer pane.
  2. In the code pane, immediately above the namespace line (such as namespace P8ApiSample), insert the following code, replacing the existing using statements.
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using FileNet.Api.Authentication;
    using FileNet.Api.Core;
    using FileNet.Api.Util;
  3. In the code pane, within the class definition (such as within class P8Connector), insert the following code, replacing the existing Main method. Substitute the actual values for your environment for the connection parameter placeholders. (The default HTTP or HTTPS port is 9080 or 9443 for WebSphere®, 8080 or 8443 for JBoss, and 7001 or 7002 for WebLogic.)
     
    static void Main(string[] args)
    {
        try
        {
            // Set connection parameters; substitute for the placeholders.
            String uri = "https://<hostname>:<portnumber>/wsi/FNCEWS40MTOM/";
            String username = "<username>";
            String password = "<password>";
    
            // Get client context.
            IConnection conn = Factory.Connection.GetConnection(uri);
            UsernameCredentials creds = new UsernameCredentials(username, password);
            ClientContext.SetProcessCredentials(creds);
    
            // Get default domain.
            IDomain domain = Factory.Domain.FetchInstance(conn, null, null);
            Debug.WriteLine("Domain: " + domain.Name);
    
            // Get object stores for domain.
            foreach (IObjectStore store in domain.ObjectStores)
            {
               Debug.WriteLine("Object store: " + store.Name);
            }
            Debug.WriteLine("Connection to Content Platform Engine successful");
        }
            catch (Exception exc)
            {
               Debug.WriteLine(exc.ToString());
            }
    }
  4. In the Visual Studio menu bar, click File > Save All.
  5. If the Output pane is not already open, click View > Output.
  6. In the Solution Explorer pane, select your project.
  7. In the Visual Studio menu bar, click Build > Build Solution.
If your code does not compile, verify that you:
< Previous | Next >



Last updated: October 2015

ss_vs_all008.htm



© Copyright IBM Corporation 2015.