Home
RECOMMENDED FOR YOU:
SMS Gateway software
Ozeki brings you outstanding
SMS Gateway technology. Use our SMS Server products on Windows,Linux, or Android

C# SMS API
Developers can use our C# SMS API to send SMS from C#.Net. The C# SMS API comes with full source code

PHP SMS API
The ozeki PHP SMS gateway software can be used to send SMS from PHP and to receive SMS usig PHP on your website

SMPP SMS Gateway
SMS service providers use our SMPP gateway solution, that offers a high performance SMPP server and SMPP client gateway with amazing routing capabilities
Ozeki Phone System 10

C# .NET VoIP developers 101

Part 1: C# example on sending SMS, making VoIP calls

Read this short guide and learn how to do basic tasks with the Ozeki Phone System, from your C# .NET application. This guide explains how to receive and make voice calls, how to send and receive SMS messages and helps you get started to build more advanced projects.

Download

C# example on sending SMS and making VoIP calls
  1. Ozeki_VoIP_CSharp_Example_Source.zip (11.5MB)
  2. Ozeki_VoIP_CSharp_Example_Exedemo.zip (11.5 MB)
  3. http://www.ozekiphone.com/examples/doc/

Part 2: C# example on logging and recording VoIP calls, call routing and configuration management

1. What you need

2. Get started

After OPSSDK.dll has been added, it will appear in the references section of your project (Figure 2).

opssdk.dll has been added succesfully
Figure 1 - OPSSDK.ddl has been added successfully

3. Receive incoming voice calls

You need to create a new instance from the OpsClient type then login to your Ozeki Phone System. To sign in, you need to specify the IP address of the server (on which your PBX has been previously installed), your username and the corresponding password. The return value of the Login function indicates whether the login was successful or not.

After that, you need to get an API Extension with the GetAPIExtension function, which needs one parameter, the identifier of the extension. If this extension does not exist, the GetAPIExtension function will return null. If the extension exists, you can subscribe to the IncomingCall event of the API Extension.

In the event handler you can access the call object in the VoIPEventArgs<ICall>'s Item property. Now you can accept, reject or forward this call object with the appropriate function. In addition, you could subscribe to the events of this object and any media handlers (MediaHandler) can also be attached.

void Initialize()
{
	var opsClient = new OpsClient();
	var result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345");
	var apiExtension = opsClient.GetAPIExtension("4324")
	apiExtension.IncomingCall += IncomingCall;
}

void IncomingCall(object sender, VoIPEventArgs<ICall> e)
{
	var call = e.Item;

	call.Accept();
	//call.Reject();
	//call.Forward("432432");
	}
	

Code 1 - C# code to handle incoming calls

4. Make outgoing voice calls

You need to create a new instance from the OpsClient, then login to your Ozeki Phone System. To sign in, you need to specify the IP address of the server (on which your PBX has been previously installed), your username and the corresponding password. The return value of the Login function indicates whether the login was successful or not.

After that, you need to get an API Extension with the GetAPIExtension function, which needs one parameter, the identifier of the extension. If this extension does not exist, the GetAPIExtension function will return null. If the extension exists, you can create a call through the API Extension. For this, you need to use the CreateCall method, then subscribe to the events of the call. The CallStateChanged event indicates that the call status has been changed. You could get the actual state from the EventArg's Item property. The CallErrorOccured event shows that an error has occured.

Many different media handlers can be attached to the call. By using the ConnectAudioReceiver method, you can attach a speaker, and the ConnectAudioSender method could be used to attach a microphone to the call. With the Start method you could start calling the callee.

void Initialize()
{
	var opsClient = new OpsClient();
	var result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345"); 
	var apiExtension = opsClient.GetAPIExtension("4324"); 
	var call = apiExtension.CreateCall("2343242");
	call.CallStateChanged += CallStateChanged;
	call.CallErrorOccurred += CallErrorOccurred;
	
	// ConnectAudioReceiver could attach other handlers to a call, like
	// Speaker, Mp3Recorder or WavRecorder
	call.ConnectAudioReceiver(Speaker.GetDefaultDevice());
	
	// ConnectAudioSender could also attach a
	// Microphone, an Mp3Player or a WavPlayer
	call.ConnectAudioSender(Microphone.GetDefaultDevice());

	call.Start();
}
		
void CallErrorOccurred(object sender, VoIPEventArgs<CallError> e)
{
	Console.WriteLine("Error occurred in the call: {0}", e.Item);
}

void CallStateChanged(object sender, VoIPEventArgs<CallState> e)
{
	Console.WriteLine("Current call state is: {0}", e.Item);
}
	

Code 2 - C# code to handle outgoing calls

5. Receive SMS message

You need to create a new instance from the OpsClient, then login to your Ozeki Phone System. To sign in you need to specify the IP address of the server (on which your PBX has been previously installed), your username and the corresponding password. The return value of the Login function indicates whether the login was successful or not.

After that, you need to get an API Extension with the GetAPIExtension function, which needs one parameter, the identifier of the extension. If this extension does not exist, the GetAPIExtension function will return null. If the extension exists, you can subscribe to the API Extension's MessageReceived event, which will indicate when a new message arrives. In the Message EventArg you can access the message content, or sender.

void Initialize()
{
	var opsClient = new OpsClient();
	var result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345");
	var apiExtension = opsClient.GetAPIExtension("4324");
	apiExtension.MessageReceived += MessageReceived;
}
			
void MessageReceived(object sender, Message e)
{
	// Here you could receive an EmailMessage, or an SMSMessage too.
	Console.WriteLine("Message received.");			
}
	

Code 3 - C# code to use Message EventArg, GetAPIExtension functions

6. Send SMS message

You need to create a new instance from the OpsClient, then login to your Ozeki Phone System. To sign in you need to specify the IP address of the server (on which your PBX has been previously installed), your username and the corresponding password. The return value of the Login function indicates whether the login was successful or not.

After that, you need to get an API Extension with the GetAPIExtension function, which needs one parameter, the identifier of the extension. If this extension does not exist, the GetAPIExtension function will return null. If the extension exists, you can subscribe to the MessageSubmitted and MessageDelivered events. The MessageSubmitted event will raise when a message is about to send, and the MessageDelivered event will raise when the recipient receives the sent message. To send an SMS message you need to create an SMSMessage object, where you can provide the destination and the message content. If you need to identify each SMS, you could do that with the SMS object's MessageId property. Finally, with the SendMessage method you can send the created SMS object to the recipient.

void Initialize()
{
	var opsClient = new OpsClient();
            
	var result = opsClient.Login("ozekixepbx.ip", "admin", "abc12345");
	var apiExtension = opsClient.GetAPIExtension("4324");
	apiExtension.MessageSubmitted += MessageSubmitted;
	apiExtension.MessageDelivered += MessageDeliveder;
	var sms = new SMSMessage("+363023424", "Hello");
	//sms.MessageId will appear in the Submit and the Delivery report.
	apiExtension.SendMessage(sms);
}

void MessageDeliveder(object sender, MessageResultEventArgs e)
{
	Console.WriteLine("Delivery result: {0}", e.Result);
}

void MessageSubmitted(object sender, MessageResultEventArgs e)
{
	Console.WriteLine("Submit result: {0}", e.Result);
}
	

Code 4 - C# code to identify SMS messages

7. Create a more advanced project

The Ozeki Phone System offers a lot more options for C#.net developers. You can interact with existing calls, control and configure the PBX, you can introduce new communication techniques and media formats.
For a complete list of .NET API commands, check out: http://www.ozekiphone.com/examples/doc/

Part 2: C# example on logging and recording VoIP calls, call routing and configuration management

If you have any questions or need assistance, please contact us at  info@ozekiphone.com

Dig deeper!
People who read this also read...

More information