I have had success in getting this working and for the benefit of the community I post this code. Couple of things - if you are running Visual Studio to build this, you need to copy the 3cxcmp-whatever.dll to the same folder you are building the solution and link to it, and secondly you have to modify the project to compile as x64.
This code provides a web service you can drop into IIS on a seperate site to the core 3CX stuff. It is written id vb.net NOT c#.
I simply hope that this helps someone. If you have a coding brain you can review the 3CX API documentation and add other web services in this script which do other stuff. I personally am interested in creatign web services to add and remove an extension from a call queue!
Millsey
----------------------------------------------------------------
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports TCX.Configuration
Imports Microsoft.Win32
Imports System.IO
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://www.fs.co.uk/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService1
Inherits System.Web.Services.WebService
#Region "Private Variables"
Private pbxconnUser As String
Private pbxconnPass As String
Private pbxconnHost As String
Private pbxconnPort As Integer
#End Region
#Region "API Declarations"
Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
#End Region
#Region "3CX Settings"
Private Function configurePhoneSystemObject() As Boolean
Try
Dim iniFile = Me.get3CXIniFilename()
If iniFile Is Nothing Then
Return False
Else
Dim confPort As String = Me.readValueFromINIFile("ConfService", "confPort", iniFile, "5485")
Dim confUser As String = Me.readValueFromINIFile("ConfService", "confUser", iniFile, "DBServ")
Dim confPass As String = Me.readValueFromINIFile("ConfService", "confPass", iniFile, "pass")
Dim port As Int32
Int32.TryParse(confPort.Trim(), port)
PhoneSystem.ApplicationName = "TCXWS"
PhoneSystem.CfgServerPort = port
PhoneSystem.CfgServerUser = confUser.Trim()
PhoneSystem.CfgServerPassword = confPass.Trim()
Return True
End If
Catch ex As Exception
Return "configurePhoneSystemObject()" & vbCrLf & ex.ToString()
End Try
End Function
Private Function readValueFromINIFile(section As String, keyName As String, FileName As String, Optional defaultValue As String = Nothing) As String
Dim sb As New StringBuilder(500)
Dim numBytes = GetPrivateProfileString(section, keyName, defaultValue, sb, sb.Capacity, FileName)
Return sb.ToString()
End Function
Private Function get3CXIniFilename() As String
Dim regKeyAppRoot As RegistryKey = Nothing
Try
If IntPtr.Size = 4 Then
regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\3CX\\PhoneSystem")
Else
regKeyAppRoot = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\3CX\\PhoneSystem")
End If
Dim _appPath As String = CStr(regKeyAppRoot.GetValue("AppPath"))
Return CStr(Path.Combine(_appPath, "Bin\3CXPhoneSystem.ini"))
Catch ex As Exception
Return "get3CXIniFilename()" & vbCrLf & ex.ToString()
End Try
End Function
#End Region
<WebMethod()> Public Function ChangeOutgoingDDI(ByVal ExtnToChange As Integer, ByVal OutgoingDDI As String) As String
' 080515 BM remove all non numeric chars from the OutGoingDDI
Dim nonNumericCharacters As New System.Text.RegularExpressions.Regex("[^0-9]")
Dim numericOnlyOutgoingDDI As String = nonNumericCharacters.Replace(OutgoingDDI, String.Empty)
configurePhoneSystemObject()
Try
Dim exts() As Extension = PhoneSystem.Root.GetExtensions()
For Each ex As Extension In exts
If ex.Number = ExtnToChange Then
ex.OutboundCallerID = numericOnlyOutgoingDDI
ex.Save()
Return "OK"
End If
Next
Return "No Such Extension"
Catch ex As TCX.PBXAPI.PBXIsNotConnected
Return "FAILED: " & ex.ToString
End Try
End Function
End Class