Call Control API - Config server is not connected

Status
Not open for further replies.

Waseem

Joined
Mar 21, 2017
Messages
16
Reaction score
0
Hi

I am using the Call Control Api .Net library , i am using a free version 14 of 3CX, now not even sure if the API is meant to work with the free version

When i try and use the connections settings i think i should be using [ConfService] (below) i keep getting the IsNotConnected exception.

However when i use the values under [General] section , I can connect and MakeACall but any interaction with the PhoneSystem I get the Config server is not connected error.

I was just messing about with the setting and somehow got it to connected and make a call but now can't do much beyond that.

Just writing a simple program to test out first my .ini file looks as below

Code:
2[General]
;connection point to call manager
;used by:
;a) call manager initializes own listener before it connects to configuration server.
;b) components which are working directly with call manager
;MUST NOT be used by components which make connection to configuration server.
;They MUST use CM_API_IP, CM_API_PORT, CM_API_USER and CM_API_PASSWORD paramaeters to make direct connection to CallManagerAPI
pbxSLNIC=127.0.0.1
cmPort=5482
pbxuser=instance_instance127750
pbxpass=42ov2rvu16n
AppPath=C:\Program Files\3CX Phone System\Instance1
AppDataPath=C:\ProgramData\3CX\Instance1
Tenant=instance1

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

[CfgServerProfile]
;configuration server connection to database
;exclusively used by configuration server
DBHost=127.0.0.1
DBPort=5480
MasterDBUser=phonesystem
MasterDBPassword=Uoi5CIvezBEwTJ
MasterTable=phonesystem_mastertable
DefFile=Objects.cls

[QMDatabase]
DBHost=127.0.0.1
DBPort=5480
DBName=database_single
dbUser=logsreader_single
dbPassword=47z7x0tco5hs

[MIME_TYPES]
MESSAGE=x-chat/control

My .NET code is below , note the connection if working OFF the Default values from my testing it cannot pick up CM_API_IP etc from the system.

So the code below works fine and makes the call ..

if i uncomment this line DN dn = PhoneSystem.Root.GetDNByNumber("852"); the call is still made but in the console an exception is thrown and I cannot do other things i want to .

Any ideas at all...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TCX.Configuration;
using TCX.PBXAPI;


namespace _3cxTest
{
    class Program
    {
        static void Main(string[] args)
        {
           
            PBXConnection pbx = CreatePbxConn();
            try
            {

                pbx.MakeCall("852", "12");
              //  DN dn = PhoneSystem.Root.GetDNByNumber("852");
         
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

        }

       


        public static TCX.PBXAPI.PBXConnection CreatePbxConn(string host, int port, string user, string password)
        {
            return new TCX.PBXAPI.PBXConnection(host, port, user, password);

            // return new TCX.PBXAPI.PBXConnection("127.0.0.1", 5482, "instance_instance127750", "42ov2rvu16n");
        }

        public static TCX.PBXAPI.PBXConnection CreatePbxConn()
        {
            //v14 (cloud and in premiss) - stores pbx API connection parameters in configuration.
            //ini file is not required to obtain this information.
            bool exists = false;
           /// return new TCX.PBXAPI.PBXConnection("127.0.0.1", 5485, "cfguser_default", "pwhshhlew3va");
         
            return CreatePbxConn(
                GetParameterValue("CM_API_IP", "127.0.0.1", ref exists),
                int.Parse(GetParameterValue("CM_API_PORT", "5482", ref exists)),
                GetParameterValue("CM_API_USER", "instance_instance127750", ref exists),
                GetParameterValue("CM_API_PASSWORD", "42ov2rvu16n", ref exists));
               
        }

        public static string GetParameterValue(string name, string DefaultValue, ref bool exists)
        {
            try
            {
                exists = true;
                return TCX.Configuration.PhoneSystem.Root.GetParameterByName(name).Value;
            }
            catch
            {
                exists = false;
                return DefaultValue;
            }
        }




    }
}
 
Update to this , the code is not throwing an exception after i added this , not sure if it solves my overall problem

Code:
  PhoneSystem.ApplicationName = "UNIQUENAME";

                PhoneSystem.CfgServerHost = "127.0.0.1";
                PhoneSystem.CfgServerPort = 5485;
                PhoneSystem.CfgServerUser = "cfguser_default";
                PhoneSystem.CfgServerPassword = "pwhshhlew3va";
 
Hi @Waseem,

That's what you had to add, the connection settings to the API knows where it has to connect, user name, password, etc. After that it should work. Please let me know if you're having any issue after adding the connection settings.

Kind regards.
 
  • Like
Reactions: Waseem
@edossantos

Thanks for the help ... I have managed to get some progress with the above.

I am now having the following problem:

In an ideal world i would like to invoke various things via a web service thus i can call it form a web application (coded in php , or whatever) .

If i create a .Net 3.5 web service application and include the DLL i downloaded from here (for V14) (https://www.3cx.com/blog/docs/call-control-api/) . It doesn't work as the assembly is complied in .net 4 (so it says)

Trying to build a web api mvc style solution gives other errors like the assembly is not found (which i can try and resolve but haven't so far )

Any ideas ?
 
Hi @Waseem,

Why do you create a .NET 3.5 project? That's very old, you should work with a modern version, I would suggest 4.6 and greater. You shouldn't have any issue using that version.

Kind regards.
 
Thanks @edossantos

This page describes 100% the problem i am having , the .NET 3.5 was a desperate attempt to get something working as i was hitting a brick wall.

http://www.toughdev.com/content/2013/01/using-3cx-call-control-api-in-a-net-application/

This guys solution was to use WCF , is there any way of using a standard API app , i have tried everything , i get the same error as described above for , API, MVC solutions I have it working via a DLL and using VAD but i need an web interface too.
 
I solved this problem by hosting the API on Abyss web server the same one that my 3CX was running on , there were no problems at all.

You have to just change the port setting the abyss config file to get access to the console and then set up a new website ..

Details of how to get to the console are here :

https://www.3cx.com/blog/docs/https-3cx-abyss/

Hope this might save someone lots of time
 
Hi @Waseem,

Glad to hear that you have solved it. Using the same web server fixes the issue because the DLLs are already loaded in memory...

Also, I think that the problem in the article described is that you were missing a dependency DLL. First, if you get this error:
System.BadImageFormatException: Could not load file or assembly ‘3cxpscomcpp2.dll’ or one of its dependencies. An attempt was made to load a program with an incorrect format

That means that your project is x86 and the DLL is x64. Please note that 3CX is a 64 bits app, so please ensure that your program running the 3CX Call Control API is also a 64 bits app.

Then, if you get this error:
Could not load file or assembly ‘3cxpscomcpp2′ or one of its dependencies. Modules which are not in the manifest were streamed in. (Exception from HRESULT: 0x80131043)

That means that the DLL or one of the dependencies are missing. This is usually caused by a dependency, as you know that you need to copy the file "3cxpscomcpp2.dll" to your working directory. The dependencies are 2 libraries:
- sl.dll (this is mentioned in the article you posted)
- tcxpscom_native.dll (pretty sure the missing DLL)

Kind regards.
 
When i run your sample example at time error will occured in var dns = PhoneSystem.Root.GetDN();
Like==>": Unable to load DLL 'tcxpscom_native': The specified module could not be found "
Can you please help me????
 
никак неполучается вклчить мжно какйнибудь тел для связи чтобы обьеснить как все работает спасибо
 
Hi @Waseem, can you explain please what do the values "852" and "12" stand for?

Code:
 pbx.MakeCall("852", "12");
 
It's from and to numbers.
 
hi,

I'm using v15, Please send me the code that how to make call from a New Windows form
 
Hi,

I can able to call now using MakeCall method.
But now i need to redirect some url after call ends.
For example: After my call ends in my softphone, website like https://www.3cx.com should open in browser.
How can i identify in v15 Call Control API. Please help
 
Hello Rajthilak

One way to do it is to monitor the connection status of the call from active connection's.

Thanks
 
Ok Noted with thanks
 
Status
Not open for further replies.

Forum statistics

Threads
112,322
Messages
591,890
Members
165,470
Latest member
Robert Lee