Tel.: 00 36 52 532 731

How to develop softphone using ASP.Net?


This page provides relevant information on how to use the C# SIP source implementation of Ozeki VoIP SDK for making an efficient VoIP example in ASP. Useful information can be found about the configuration and source code below on the page.

Introduction of the ASP.Net softphone

The ASP voip callback sample program is a web application created by Microsoft ASP .NET technology. It was developed with the purpose to demonstrate how easy it is to create a free callback service for your customers. On the callback required interface customers have the opportunity to give their availability that will be dialed and connected by the application to the operator. To make the process simpler the availability of the operator also needs to be provided.

The sample program registers to a SIP PBX with a given SIP account. After the finalization of the call back request the program dials the two phone numbers. If the two calls were successfully established then the program connects them or if necessary it terminates the line.

How to develop softphone using ASP.NET?

You can find here how to set up and use the C# SIP source implementation of Ozeki VoIP SDK for ASP VoIP example, you just need to follow the configuration guide.

What configuration steps should be made?

  1. Download and extract the sample program
  2. Load the project into Visual Studio 2010
  3. The sample program was developed only for demonstrating purposes so it does not consist configuration options on the GUI. This means that for the proper operation of the program a minimal configuration is required in the source code, in the phone initialization section of the Global.asax.cs file:
        softPhone = SoftPhoneFactory.CreateSoftPhone("", 5700, 5750, 5700);  
        softPhone.IncomingCall += new EventHandler<VoIPEventArgs<IPhoneCall>>(softPhone_IncomingCall);  
        phoneLine = softPhone.CreatePhoneLine(new SIPAccount(true, "oz891", "oz891", "oz891", "oz891", "", 5060));  
        phoneLine.PhoneLineInformation += new EventHandler<VoIPEventArgs<PhoneLineInformation>>(phoneLine_PhoneLineInformation);  
        softPhone.ChangeNATSettings(NATTraversalMethodType.NONE, string.Empty, string.Empty, string.Empty);  
    catch (Exception ex)  
    	ErrorIndicator = String.Format("You didn't give your local IP adress, so the program won't run properly.\n {0}",ex.Message);  
    Also set if a NAT is between the softphone and the SIP server. This setting depends on the environment (depends on the construction of the network). If this setting is specified incorrectly, audio data from the remote end will not be received during the phone call. As a next step you need to provide the user data of your selected SIP PBX as the SIP account object values similarly to the following line:
    phoneLine = softPhone.CreatePhoneLine(new SIPAccount(True, "oz891", "oz891", "oz891", "oz891", "", 5060));
    Where "true" is the registrationRequired parameter that in case of true value and successful registration makes it possible to receive calls and not just manage them. (In the case of registering with "false" value only call managing is allowed.)

    In the example the "oz891" marks the SipAccount displayname, username, registername and registerpassword parameters in listing order.

    The next two parameters are the SIP PBX IP or domain address and the port.
  4. When you are finished you only need to build and run the program.

Softphone example in ASP.Net

You can find here information about the source code which help in the better understanding of the C# SIP source implementation of Ozeki VoIP SDK for ASP VoIP example

  1. Graphical User Interface: the sample application was developed by the previously mentioned ASP.NET web technology to present how simple it is to create a callback by using Ozeki VoIP SIP SDK. On the interface an "operator" phone number and the phone number of a customer can be specified. The request of callback loses its validity by clicking on the Submit button and the dialing and connecting of the two numbers begin.
  2. Running the program: the program automatically does the registration process so only the two phone numbers need to be specified on the webpage that will be connected similarly to a real callback process. In the ASP application the softphone made by Ozeki VoIP SIP SDK is in the Global.asax file that realizes the application level logic. According to this the automatic registration to the SIP PBX is bound to the Session_Start event of the application.

    After successful registration there is nothing else to do just to give the two phone numbers and to confirm the call request. Then the program dials the phone number of the operator then after the call is created successfully the software dials the phone number of the operator, as well. Depending on if the call was also successfully created it redirects the sound date of these calls to each other and this way it connects the two calls. In case of unsuccessful registration check if it was configured on the IP address of your computer.
  3. Writing the source code: the sample program lacks the design model and the usage of other conventions because it is only for represantation purposes. As you open this file a few lines of decleration can be seen that is needed to use Ozeki VoIP SIP SDK.
    private static ISoftPhone softPhone;  
    private static IPhoneLine phoneLine;  
    private static PhoneLineInformation phoneLineInformation;  
    private static IPhoneCall calloperator;  
    private static IPhoneCall callcustumer;  
    private static PhoneCallAudioSender operatorSender = new PhoneCallAudioSender();  
    private static PhoneCallAudioReceiver operatorReceiver = new PhoneCallAudioReceiver();  
    private static PhoneCallAudioSender customerSender = new PhoneCallAudioSender();  
    private static PhoneCallAudioReceiver customerReceiver = new PhoneCallAudioReceiver();  
    private static MediaConnector mediaConnector = new MediaConnector();  
    public string operatorNumber,customerNumber;  
    public String ErrorIndicator;  
    ISoftPhone: It represents a telephone, and its phone line is represented by the IPhoneLine object. There can be more telephone lines which means that we can develop a multi line phone.

    IPhoneLine: It represents a telephone line that we can register to a SIP PBX, for example Asterisk, 3CX, or to any other PBXs that are offered by SIP providers. Registration happens through SIP account.

    PhoneLineInformation: It is an enum type that represents the status of the telephone line with the PBX. For example, registered, not registered, successful/unsuccessful registration.

    IPhoneCall: It represents a call: the status of the call, the direction of the call, on which telephone line it was created, the called person etc.

  4. The program initilaizes the softphone after the loading of the GUI: the application registers automatically through the application level Session_Start event by through the invitation of InitializeSoftPhone() method:
    private void InitializeSoftPhone()  
           softPhone = SoftPhoneFactory.CreateSoftPhone(SoftPhoneFactory.GetLocalIP(), 5700, 5750, 5700);  
           softPhone.IncomingCall += new EventHandler<VoIPEventArgs<IPhoneCall>>(softPhone_IncomingCall);  
           phoneLine = softPhone.CreatePhoneLine(new SIPAccount(true, "oz875", "oz875", "oz875", "oz875", "", 5060),new NatConfiguration(NatTraversalMethod.None));  
           phoneLine.PhoneLineStateChanged += new EventHandler<VoIPEventArgs<PhoneLineState>>(phoneLine_PhoneLineInformation);  
           mediaConnector.Connect(operatorReceiver, customerSender);  
           mediaConnector.Connect(customerReceiver, operatorSender);  
       catch (Exception ex)  
           //MessageBox.Show(String.Format("You didn't give your local IP adress, so the program won't run properly.\n {0}", ex.Message), string.Empty, MessageBoxButtons.OK,  
    Create an instance of your phone through the "softPhone" object that you give the IP address of your computer. Also give the port domain that your telephone can use. Finally provide the last parameter which is the port that observes SIP messages coming from the PBX.

    Sign up to the event that handles the incoming calls of your telephone "softPhone.IncomingCall" which happens when you receive incoming calls from a distant user.

    Create a phoneLine with a SIP account that can be the user account of your corporate SIP PBX or a free SIP provider account. Because of the status of the created telephone line signal sign up to its "phoneLine.PhoneLineInformation" event.

    When these things are done you only need to register the created phoneline "phoneLine" onto your telephone "softPhone". In this example only one telephone line is registered but of course multiple telephone line registration is available.

    After these steps you only need to deal with the handling of the calls and to display them onto the GUI.
  5. Handling the calls: Ozeki SDK represents the incoming and outgoing calls through the IPhoneCall interface. This interface contains the status of the given call, on which line it was created and who the called person is. On this object you can pick up or hang up calls.
    • Handling outgoing calls: the application dials the phone numbers which were given on the interface by pressing the Submit button through the "global.BeginCall(OperatorCall)" method call.
      public void BeginCall(bool IsCustomerCall)  
          if (IsCustomerCall)  
              if (phoneLineState != PhoneLineState.RegistrationSucceeded && phoneLineState != PhoneLineState.NoRegNeeded)  
              callcustumer = softPhone.CreateCallObject(phoneLine,customerNumber);  
              if (phoneLineState != PhoneLineState.RegistrationSucceeded && phoneLineState != PhoneLineState.NoRegNeeded)  
              calloperator = softPhone.CreateCallObject(phoneLine, operatorNumber);  
      This method does the call forwarding towards the operator and the customer and its parameter determines to which direction it needs to go. Before establishing a call you need to subscribe to some events for the call to be effective. The software makes these subscribes through the "WireUpCallEvents" call policy.
      private void WireUpCallEvents(IPhoneCall call)  
          call.CallStateChanged += new EventHandler<VoIPEventArgsc<CallState>>(call_CallStateChanged);  
          call.DtmfReceived += new EventHandler<VoIPEventArgs<OzTuple<VoIPMediaType, DtmfSignal>>>(call_DtmfReceived);  
          call.CallErrorOccured += new EventHandler<VoIPEventArgs<CallError>>(call_CallErrorOccured);  
      The "CallStateChanged" event lines out the changes that happen in the status of the call.

      The sound data which comes from the distant telephone arrives through the "MediaDataReceived" event.

      Through the above shown CallErrorOccured event you can receive information about the reasons why the call was not created. For example: the called party is busy, the call is rejected, the called number does not exist or the called number is not available.

      To wire up for these necessary events you only need to really start a call. You can do it with the Start() function of the "call" object.
    • Rejecting incoming calls: the Ozeki VoIP SDK publishes the incoming calls through the "ISoftphone" InComingCall event for us. According to the character of the sample program the incoming calls are not interpreted so the they are immediately rejected.
      private void softPhone_IncomingCall(object sender, VoIPEventArgs<IPhoneCall> e)  
    • Closing conversations: when one of the parties aborts or ends the current call then the program closes the call of the other party. This happens with the "HangUP()" method call on the IPhoneCall object of the specific party.
    • Displaying the status of calls: the VoIP SIP SDK publishes the status changes that happen during the telephone call through the IphoneCall CallStateChanged event. This program handles three status in the case of "Incall" status as it also can be seen from the source code. If a change happened in the call object of the operator then it sends the call towards the customer. If one of the calls ended then it ends the other call as well with the HangupCall((IPhoneCall)sender) method. It ends the desirable call through the "IPhoneCall" object's Stop() method.

Training guides, simple examples

If you would like to visit the detailed developer documentations, you can learn much more from the Ozeki VoIP SIP SDK Training chapter.

If you have any questions or need assistance, please contact us at

Related Pages