ConfigServer is not connected

Discussion in 'CRM / Helpdesk / App Integration' started by Maciej Cygan, Mar 16, 2017.

Thread Status:
Not open for further replies.
  1. Maciej Cygan

    Joined:
    Jan 19, 2017
    Messages:
    12
    Likes Received:
    1
    Hello Everyone,

    I am rather new to 3CX so bare with me. I have downloaded the API samples and followed instructions on how to start them up

    I have imported all files to my Visual Studio IDE and compiled them as x64. I have copied the .ini file from 3cx directory to the output folder of my program. I have also copied all .dll from the 3cx directory to the output folder (as i had some issues with the .dll not found - and as someone has already suggested just to copy all and it seems like it works). the 3cxpscomcpp2.dll is added as a reference to the project.

    Now when i try to run the .exe file from CMD like so:

    C:\Users\Boss\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\x64\Debug>ConsoleApplication1.exe display

    I get the following error.

    Exception: TCX.Configuration.Exceptions.PhoneSystemException: ConfigServer is not connected
    at TCX.Configuration.PhoneSystem.Connect()
    at TCX.Configuration.PhoneSystem.get_Root()
    at OMSamples.Samples.DisplayAllSample.Run(String[] args) in C:\Users\Boss\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\Samples\DisplayAll.cs:line 17
    at ConsoleApplication1.SampleStarter.StartSample(String[] args) in C:\Users\Boss\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\SampleStarter.cs:line 101

    I have added 'PhoneSystem.ApplicationName = "TestApi";' to the Program.cs and the same entry to .ini file under [ConfService] stanza like so:

    [ConfService]
    ;connection point to configuration server for components
    PhoneSystem.ApplicationName=TestApi
    confNIC=127.0.0.1
    ConfPort=5485
    confUser=cfguser_default
    confPass=z7ofad6y7x


    Also on a note:

    DN[] ps = PhoneSystem.Root.GetDN(); //Access PhoneSystem.Root to initialize ObjectModel

    When this line is commented out the program compiles fine but it breaks when running from CMD. When this line is not commented out it throws an error while compiling. The error is the same 'ConfigServe' is not connected.

    The port, user, pass remain unchanged so i am not sure if these are the default values the API is configured for or do i have to replace them with something else ? What am i missing ?

    PS: I do not seem to have any 3cx Logs generated - and i can not find any setting to enable logging ?
     
    #1 Maciej Cygan, Mar 16, 2017
    Last edited: Mar 16, 2017
  2. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,438
    Likes Received:
    114
    This is usually a problem with credentials. You need to configure the PhoneSystem object to use the credentials from your ini file. Try setting those values in code instead of reading them from the ini. Copy the user name and password and set the values to the PhoneSystem object.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. matteo ghielmi

    Joined:
    Apr 19, 2017
    Messages:
    4
    Likes Received:
    0
    Hello Everyone,
    I have the same problem. As suggested I have try setting those values in code instead of reading them from the ini, but the same error is still there.

    Do you have any suggestions?
     
  4. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,438
    Likes Received:
    114
    Hello @matteo ghielmi,

    Are you connecting from the same 3CX server? The API is not available remotely.

    Are you using the credentials from the right ini file? Please note that there is a general file and an instance file. You need to take the info from the instance file.

    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. matteo ghielmi

    Joined:
    Apr 19, 2017
    Messages:
    4
    Likes Received:
    0
    Hi,

    I Have copied 3CXPhoneSystem.ini from C:\Program Files\3CX Phone System\Instance1\Bin to the same folder where Visual Studio will output the binary files.

    Here 3CXPhoneSystem.ini

    [ConfService]
    ;connection point to configuration server for components
    PhoneSystem.ApplicationName=TestApi
    confNIC=127.0.0.1
    ConfPort=5485
    confUser=cfguser_default
    confPass=ayzjsvooypew4

    Below the source code

    using System;
    using System.Collections.Generic;
    using System.Text;
    using TCX.Configuration;
    using TCX.PBXAPI;
    using System.Threading;
    using System.IO;
    using System.Reflection;

    namespace OMSamples
    {
    class Program
    {

    static void Bootstrap(string filePath, string[] args)
    {

    var a = new Random(Environment.TickCount);

    #region phone system initialization(init db server)

    PhoneSystem.ApplicationName = "TestApi";
    PhoneSystem.ApplicationName = PhoneSystem.ApplicationName + a.Next().ToString();
    PhoneSystem.CfgServerHost = "127.0.0.1";
    PhoneSystem.CfgServerPort = 5485;
    PhoneSystem.CfgServerUser = "cfguser_default";
    PhoneSystem.CfgServerPassword = "ayzjsvooypew4";
    Console.WriteLine(PhoneSystem.ApplicationName);
    Console.WriteLine(PhoneSystem.CfgServerHost);
    Console.WriteLine(PhoneSystem.CfgServerPort);
    Console.WriteLine(PhoneSystem.CfgServerUser);
    Console.WriteLine(PhoneSystem.CfgServerPassword);

    bool TestConn = false;
    int cont = 0;
    do
    {
    try
    {
    TestConn = PhoneSystem.Root.Connected;
    }
    catch (Exception exc)
    {
    Console.WriteLine("Configuration server not connected : " + exc.Message);
    Thread.Sleep(10000);
    cont++;
    }
    } while (!TestConn && cont < 4);
    #endregion
    var dns = PhoneSystem.Root.GetDN(); //Access PhoneSystem.Root to initialize ObjectModel

    SampleStarter.StartSample(args);
    PhoneSystem.Root.Disconnect();
    Console.ReadLine();
    }

    static string instanceBinPath;

    static void Main(string[] args)
    {
    try
    {

    var filePath = @".\3CXPhoneSystem.ini";
    if (!File.Exists(filePath))
    {
    //this code expects 3CXPhoneSystem.ini in current directory.
    //it can be taken from the installation folder (find it in Program Files/3CXPhone System/instance1/bin for in premiss installation)
    //or this application can be run with current directory set to location of 3CXPhoneSystem.ini

    //v14 (cloud and in premiss) installation has changed folder structure.
    //3CXPhoneSystem.ini which contains connectio information is located in
    //<Program Files>/3CX Phone System/instanceN/Bin folder.
    //in premiss instance files are located in <Program Files>/3CX Phone System/instance1/Bin
    throw new Exception("Cannot find 3CXPhoneSystem.ini");

    }
    instanceBinPath = Path.Combine(Utilities.GetKeyValue("General", "AppPath", filePath), "Bin");
    Console.WriteLine(instanceBinPath);
    AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
    Bootstrap(filePath, args);
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.ToString());
    Console.ReadLine();
    }
    }

    static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
    var name = new AssemblyName(args.Name).Name;

    if (name == "3cxpscomcpp2")

    return Assembly.LoadFrom(Path.Combine(instanceBinPath, name + ".dll"));
    else
    throw new FileNotFoundException();

    }
    }
    }
     
  6. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,438
    Likes Received:
    114
    And what error do you get when you run your program?

    Did you copy the dependant DLLs to your working directory? You need these 3 files:
    - 3cxpscomcpp2.dll
    - sl.dll
    - tcxpscom_native.dll

    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. matteo ghielmi

    Joined:
    Apr 19, 2017
    Messages:
    4
    Likes Received:
    0
    Hi, Edossantos

    Yes,

    Folder contains the three files shown.

    I get the following error when program run.

    Exception: TCX.Configuration.Exceptions.PhoneSystemException: ConfigServer is not connected
    in TCX.Configuration.PhoneSystem.Connect()
    in TCX.Configuration.PhoneSystem.get_Root()
    in OMSamples.Program.Boostrap(String filePath, String[] args) in C:\Users\mattew\OMSSamples\Samples\program.cs:line 50
    at OMSamples.Program.Main(String filePath, String[] args) in C:\Users\mattew\OMSSamples\Samples\program.cs:line 81

    Thank you

    Regard
     
  8. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,438
    Likes Received:
    114
    Can you check the Configuration Service log from "C:\ProgramData\3CX\Instance1\Data\Logs" to see if there is any hint about why the service is rejecting the connection?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. matteo ghielmi

    Joined:
    Apr 19, 2017
    Messages:
    4
    Likes Received:
    0
    Hi,

    I do not seem to have any 3cx Logs generated in folder C:\ProgramData\3CX\Instance1\Data\Logs, and i can not find any setting to enable logging. The only log screen is the one above. I cleaned the code by testing only the connection, but the error is always there.
    Do you have some working example to test the connection?

    Thank you

    Regard
     
  10. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,438
    Likes Received:
    114
    The working example can be downloaded from here:
    https://www.3cx.com/blog/docs/call-control-api/

    It's not possible that you don't have logs in folder "C:\ProgramData\3CX\Instance1\Data\Logs". Are you looking in the 3CX server? Please check because logs must be there...

    Regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. HurricaneH

    Joined:
    May 31, 2017
    Messages:
    2
    Likes Received:
    0
    Matteo
    I am having the exact same problem, can't run it in a different directory without getting errors on tcxpscom_native.dll.
    If i copy runtime into the Bin folder and run it there, it seems to get past the error and then stops on the Confirg Server error you've listed above
     
  12. craigreilly

    craigreilly Well-Known Member

    Joined:
    Feb 1, 2012
    Messages:
    3,405
    Likes Received:
    274
    Just to confirm:
    The CALL CONTROL API can only be installed on the 3cx SERVER.

    https://www.3cx.com/blog/docs/call-control-api/

    Important:

    • The API is only available on the server, i.e any application that is using it must be running on the server itself. This is because the service will not accept connections from 0.0.0.0 (ANY IP). Connections are only accepted from 127.0.0.1 (localhost).
    • The Call Control API is only available in commercial editions.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Thread Status:
Not open for further replies.