Skip to content
A simple Voice app that demonstrates the use of BXML using Bandwidth's Voice API, C#, and ASP.NET
Branch: master
Clone or download
Latest commit 6d3bc3a Sep 18, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vs done Sep 18, 2018
BXMLsample done Sep 18, 2018
.DS_Store testing Sep 18, 2018
BXMLsample 3.35.35 PM.sln first test Sep 13, 2018 done Sep 18, 2018

Simple BXML Sample

A simple Voice app that demonstrates the use of BXML using Bandwidth's Voice API, C#, and ASP.NET.

Table of Contents


How It Works

This app provides a very simple example of how to use BXML with a Bandwidth Voice callback in order to send audio back to an end user.


Make sure you have a Bandwidth account with at least one number set up to receive Voice calls. Make sure that the application for this number is set to auto-answer, because BXML itself cannot answer a call. Also make sure the Callback Request Method of your application is set to GET.

Create a New Solution in Visual Studio

The best solution type to use is ASP.NET Core Web API. Call it BXMLsample or whatever you choose. Open the ValuesController.cs file and delete the code that is already there. This guide will walk you through all the code you need.

Set Up the Namespace

The only namespace you need is the following:

using Microsoft.AspNetCore.Mvc;
using Bandwidth.Net;

Initiate API Routes

namespace BXMLsample.Controllers
    public class ValuesController : ControllerBase


Create a Function that Creates a BXML Sequence

//within public class ValuesController : ControllerBase
public string CreateBXML()
    string bxmlString = "";
    bxmlString += "<?xml version='1.0' encoding='UTF-8' ?>";
    bxmlString += "<Response>";
    bxmlString += "<SpeakSentence voice='susan' locale='en_US' gender='female'>";
    bxmlString += "Hi, thanks for calling. Goodbye";
    bxmlString += "</SpeakSentence>";
    bxmlString += "<Hangup></Hangup>";
    bxmlString += "</Response>";

    return bxmlString;

Create Callback Endpoint That Returns BXML

This endpoint checks that the EventType of the callback is CallbackEventType.Answer. If it is, then the endpoint returns CreateBXML(). If it isn't, then the endpoint returns null.

//also within public class ValuesController : ControllerBase
public string BXML([FromQuery] CallbackEvent callback)

    if (callback.EventType == CallbackEventType.Answer)
        return CreateBXML();
        return null;


One easy way to deploy this solution is using a Microsoft Azure account. You can sign up for an account here and read the Azure docs here.

Once your solution is deployed, set the Voice callback URL of your BXML application to https://[YOUR_DEPLOYED_SOLUTION_URL]/api/bxml.

Now when someone calls a phone number associated with your BXML application, they will hear brief computer-generated speech and the application will automatically hang up.

You can’t perform that action at this time.