# Look up Administered Objects Stored in EMS

You can lookup objects from an EMS server by name. All clients can lookup objects in the EMS naming service. Alternatively, Java applications can lookup objects in a third-party JNDI server, and C and C# clients can lookup objects in a third-party LDAP server.

To lookup administered objects stored in EMS, you need to create the initial context that identifies the URL of the naming service provider and any other properties, such as the username and password to authenticate the client to the service. The naming service provider URL has form:

        tibjmsnaming://host:port

The following examples demonstrate how to access JMS administered objects when using TIBCO Enterprise Message Service. Each of these examples assume that a connection factory, named `ConFac`, exists in the `factories.conf` file, a `topic.sample` topic exists in topics.conf, and a `queue.sample` queue exists in queues.conf.

- Java

  Create an `InitialContext` object for the initial context, which consists of the provider context factory and JNDI provider URL, as well as the username and password to authenticate the client to the EMS server:

      Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
              "com.tibco.tibjms.naming.TibjmsInitialContextFactory");
        env.put(Context.PROVIDER_URL,"tibjmsnaming://localhost:7222");
        env.put(Context.SECURITY_PRINCIPAL, "userName");
        env.put(Context.SECURITY_CREDENTIALS, "password");
      InitialContext jndiContext = new InitialContext(env);

  Look up a connection factory, named `ConFac`, and destinations, named `topic.sample` and `queue.sample`, from the initial context:

      ConnectionFactory factory =
            (javax.jms.ConnectionFactory)
            jndiContext.lookup("ConFac");
      javax.jms.Topic sampleTopic =
                (javax.jms.Topic)jndiContext.lookup("topic.sample");
      javax.jms.Queue sampleQueue =
                (javax.jms.Queue)jndiContext.lookup("queue.sample");

  See the `tibjmsJNDI.java` sample client located in the `EMS_HOME``/samples/java/JNDI` directory.

- C

  Create a `tibemsLookupContext` object for the initial context, which consists of the JNDI provider URL and the username and password to authenticate the client to the EMS server:

      tibemsLookupContext* contextstatus = NULL;
      status = tibemsLookupContext_Create(
                                 &context,
                                 "tibjmsnaming://localhost:7222",
                                 "userName",
                                 "password");

  Use the `tibemsLookupContext_LookupConnectionFactory` function to look up a connection factory, named `ConFac`, and use the `tibemsLookupContext_Lookup`Destination function to look up the destinations, named and `queue.sample`, from the initial context:

      topic.sample
      tibemsConnectionFactory factory = NULL;
      tibemsDestination sampleTopic = NULL;
      tibemsDestination sampleQueue = NULL;

      status = tibemsLookupContext_Lookup(context,
                                          "ConFac",
                                          (void**)&factory);
      status = tibemsLookupContext_Lookup(context,
                                          "sample.queue",
                                          (void**)&sampleQueue);
      status = tibemsLookupContext_Lookup(context,
                                          "topic.sample,                                     (void**)&sampleTopic);

- C#

  Create a `ILookupContext` object for the initial context, which consists of the JNDI provider URL and the username and password to authenticate the client to the EMS server.

      Hashtable env = new Hashtable();
        env.Add(LookupContext.PROVIDER_URL,
                "tibjmsnaming://localhost:7222");
        env.Add(LookupContext.SECURITY_PRINCIPAL", "myUserName");
        env.Add(LookupContext.SECURITY_CREDENTIALS", "myPassword");

      LookupContextFactory factory = new LookupContextFactory();
      ILookupContext searcher = factory.CreateContext(
                                 LookupContextFactory.TIBJMS_NAMING_CONT
                                EXT,
                                env);

  Use the `ILookupContext.Lookup` method to look up a connection factory, named ConFac, and destinations, named `topic.sample` and `queue.sample`, from the initial context:

      ConnectionFactory factory =
            (ConnectionFactory) searcher.Lookup("ConFac");
      Topic sampleTopic =
            (Topic)searcher.Lookup("topic.sample");
      TIBCO.EMS.Queue sampleQueue =
            (TIBCO.EMS.Queue)searcher.Lookup("queue.sample");

Copyright © Cloud Software Group, Inc. All rights reserved.