Export (0) Print
Expand All

MakeCall Example

Speech Server 2004 R2
  Microsoft Speech Technologies Homepage

This topic describes a simple application that demonstrates the MakeCall Application Speech Control. Running this application requires Speech Server, Telephony Application Services (TAS), MessageQueueing, Visual Studio .NET 2003, and Speech Application SDK.

The application expects a private message queue called OutboundCallRequests, and the ASP.NET user must have access to this queue. In the case of a local queue, this can be done by granting the NetworkService account Receive Message permission. To configure other types of queues, see the topic "Securing a Message Queue" in the Speech Server documentation.

Create a new Speech Web Application in Visual Studio .NET 2003
Open Visual Studio .NET 2003 and create a new project. In the left panel of the New Project wizard, select C# project, and in the right panel, select Speech Web Application. Change the project name from SpeechWebApplication1 to SendMessage, and click OK.
Specify the application properties
In the left panel of the Project Wizard window, click the Application Settings link and clear the Enable Telephony Application Simulator check box. Then click the Application Resources link and clear the Create new prompt project check box. Click the Finish button to create the application.
Add markup to the default page
Click the HTML button on Default.aspx to view the file in HTML mode. Replace the empty form tags with this markup:
<form id="Form1" method="post" runat="server">
  <table>
    <tr>
      <td style="WIDTH: 220px">
        <asp:Label id="Label1" runat="server">Phone number:</asp:Label>
      </td>
      <td>
        <asp:TextBox id="PhoneNumber" runat="server" Width="265px">
        </asp:TextBox>
      </td>
    </tr>
    <tr>
      <td style="WIDTH: 220px">
        <asp:Label id="Label2" runat="server">Message:</asp:Label>
      </td>
      <td>
        <asp:TextBox id="Message" runat="server" 
          Rows="3" Columns="80" MaxLength="300" Width="582px"
          TextMode="MultiLine"> 
        </asp:TextBox>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <asp:Button id="Button1" runat="server" Text="Go"></asp:Button>
      </td>
    </tr>
  </table>
</form>
Add the Dialog page to the project
Under the Project menu, select Add New Item, and select the WebForm template. Change the file name in the Name text box from WebForm1.aspx to Dialog.aspx and click Open. This displays the empty Dialog.aspx form in Designer view.
Add markup to the Dialog page
Click the HTML button on the Dialog.aspx file to display the HTML view. Paste the following tag into the top of the page, above the line of markup with the yellow background:
<%@ Register TagPrefix="speech" Namespace="Microsoft.Speech.Web.UI" Assembly="Microsoft.Speech.Web, Version=1.0.3200.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
Paste the following markup into the module, replacing the empty form tags:
<form id="Form1" method="post" runat="server">

  <speech:MakeCall id="MainMakeCall" runat="server" AutoPostBack="false">
  </speech:MakeCall>

  <speech:QA id="PlayMessage" runat="server" PlayOnce="True">
    <Dtmf ID="PlayMessage_Dtmf"></Dtmf>
    <Reco ID="PlayMessage_Reco"></Reco>
    <Prompt ID="PlayMessage_Prompt"></Prompt>
  </speech:QA>
  
  <speech:DisconnectCall id="DisconnectCall1" runat="server">
  </speech:DisconnectCall>
</form>
Add the Error page to the project
Under the Project menu, select Add New Item, and select the HTML file template. Change the file name in the Name text box from HTMLPage1.htm to 500Error.htm and click Open. This displays the empty 500Error.htm page in Designer view. Click the HTML button on the Dialog.aspx file to display the HTML view. Paste the following markup into the body of the 500Error.htm page:
The page could not be served.
<br>
Ask the admin to look at the comments in the web.config file for more help.
<br>
<br>
Show code-behind modules
To display the code-behind modules in the project, click the Show All Files button on the Solution Explorer toolbar.
Add code to the Default page
In Solution Explorer, double-click the file Default.aspx.cs. Replace this code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
with the following code:
using System;
using System.Diagnostics;
using System.DirectoryServices;
using System.Messaging;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
Paste the following markup into the module, above the Web Form Designer generated code notation:
private void Button1_Click(object sender, System.EventArgs e)
{
  string messageQueuePath = @".\private$\OutboundCallRequests";
  string phoneNumber = PhoneNumber.Text.Trim();
  if (0 == phoneNumber.Length)
  {
    return;
  }
  string message = Message.Text.Trim();
  if (0 == message.Length)
  {
    return;
  }

  // Build URI of start page.
  string startPageUriString = string.Format("http://{0}/{1}Dialog.aspx?PhoneNumber={2}&Message={3}",
        Environment.MachineName, Request.Url.Segments[1],
        Server.UrlEncode(Server.HtmlEncode(phoneNumber)),
        Server.UrlEncode(Server.HtmlEncode(message)));

  MessageQueue queue = new MessageQueue(messageQueuePath);
  queue.Send(startPageUriString);

  // Set appropriate fields to empty.
  Message.Text = string.Empty;
}
Add code to the Dialog page
In Solution Explorer, double-click the file Dialog.aspx.cs. Paste the following markup into the module, replacing the entire Page_Load routine:
private void Page_Load(object sender, System.EventArgs e)
{
  string phoneNumber = Server.HtmlDecode(Server.UrlDecode(Request.QueryString["PhoneNumber"]));
  MainMakeCall.CalledDirectoryNumber = phoneNumber;

  string message = Server.HtmlDecode(Server.UrlDecode(Request.QueryString["Message"]));
  if (Request.QueryString["Spammer"] != null) 
  {
    message += ". This automated message was sent to you by " +  Server.UrlDecode(Request.QueryString["Spammer"]);
  }
  PlayMessage.Prompt.InlinePrompt = message;
}
Modify the web.config file
In Solution Explorer, double-click the web.config file. Replace this markup:
<configuration>
    
  <system.web>
with the following markup:
<!-- 
  This app requires credentials for a domain account to be stored in the 
  registry. See the <identity> section (impersonation) in this file. 
  If you're suddenly getting this error, perhaps the password for the 
  account used has been changed, and you need to update the credentials 
  stored in the registry - You need to run something like:

  aspnet_setreg.exe  -k:Software\SendMessage\Identity  -u:redmond\YOUR_ACCOUNT  -p:YOUR_PASSWORD

  Also make sure that network service has permission to read the 
  key HKLM\Software\SendMessage\Identity and then reset IIS.
-->

<configuration>

  <location path="Dialog.aspx">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

  <system.web>
Replace this markup:
<customErrors 
mode="RemoteOnly" 
/> 
with the following markup:
<customErrors mode="RemoteOnly" >
  <error statusCode="500" redirect="500Error.htm"/>
</customErrors>
Replace this markup:
<authentication mode="Windows" />
with the following markup:
<authentication mode="Windows" />
<identity impersonate="false" />
Replace this markup:
<authorization>
    <allow users="*" /> <!-- Allow all users -->
  <!--  <allow     users="[comma separated list of users]"
       roles="[comma separated list of roles]"/>
        <deny      users="[comma separated list of users]"
       roles="[comma separated list of roles]"/>
  -->
</authorization>
with the following markup:
<authorization>
  <deny users="?" />
</authorization>
Add code to the Global.asax file
In Solution Explorer, double-click the file Global.asax.cs. Paste the following code into the module, replacing the existing Application_Error routine:
protected void Application_Error(Object sender, EventArgs e)
{
  if (Request.UserAgent.IndexOf("Microsoft-Visual-Studio.NET") != -1) return;
  string uriFormat       = "\r\n\r\nURI: {0}\r\n\r\n";
  string exceptionFormat = "SendMessage: {0}: \"{1}\"\r\n{2}\r\n\r\n";

  System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("Application");
  eventLog.Source = "Application";
  System.Text.StringBuilder message = new System.Text.StringBuilder();
  if (Request != null) 
  {
    message.AppendFormat(uriFormat, Request.Path);
  }
  if (Server != null) 
  {
    Exception ex;
    for (ex = Server.GetLastError(); ex != null; ex = ex.InnerException) 
    {
      message.AppendFormat(exceptionFormat, 
        ex.GetType().Name, 
        ex.Message,
        ex.StackTrace);
    }
  }
  eventLog.WriteEntry(message.ToString(), System.Diagnostics.EventLogEntryType.Error);
}
Add references
In Solution Explorer, right-click the References node and select Add Reference. In the Add Reference dialog, select the component System.DirectoryServices.dll and click Select. Then select the component System.Messaging.dll and click Select. Click OK to close the dialog.
Build the solution
On the Build menu, click Build Solution.
Show:
© 2015 Microsoft