Click here to Skip to main content
13,193,970 members (46,832 online)
Click here to Skip to main content
Add your own
alternative version


44 bookmarked
Posted 28 Apr 2007

Call Control Implmentation Using the Windows Workflow Foundation

, 28 Apr 2007
Rate this:
Please Sign up or sign in to vote.
A call control implmentation using the State machine Workflow.

Screenshot - newCall.jpg


This article describes the design of a Call Control mechanism for any Telephony application that uses TAPI as its base framework. This article doesn't make use of any TAPI but provides a generic call control mechanism that can be hooked to any PBX or Call based system.


This application uses Microsoft's new framework technology - Windows Workflow Foundation's state machine workflow. The state flow diagram below describes a very common mechanism starting from a new call until the call ends as the disconnected state. This example makes use of the following call states.

  • WaitingForCallState
  • CallNewstate
  • CallInboundState
  • CallOutboundState
  • CallOnholdState
  • CallConnectedState
  • CallDisconnected

Call State Diagram

Screenshot - stateDiagram.jpg

Event Driven Activity

Each state consists of one or more activities. For example, WairingForCallState defines an Event driven activity on "OnNewCallCreated". This activity enables execution of the contained activities base on an event. Here, they are "handleCallCreated" and "setCallNewState". "handleCallCreated" subactivity enables receiving an event into the workflow and "setCallNewState" causes the state machine to transition to another state. In this case, it is the transition to "CallNewState". How to map an external event with "handleCallCreated" is described in the next section, with code snippets.

Screenshot - singleStateEvent.jpg

Using the code

There are three components for this application:

  1. Call Control UI application (displayed on top as a screenshot).
  2. Call Control Workflow (implements the workflow, states, and activity as in the above state machine diagram).
  3. Call Control Services (described below with code).

ICallControlService: Interface

This interface describes all the events responsible for the transition of the call state.

using System;
using System.Workflow.Activities;

namespace CallControlServices

 public interface ICallControlService

  event EventHandler<CallEventArgs> CallCreated;
  event EventHandler<CallEventArgs> CallDialingOut;
  event EventHandler<CallEventArgs> CallOffering;
  event EventHandler<CallEventArgs> CallConnected;
  event EventHandler<CallEventArgs> CallOnHold;
  event EventHandler<CallEventArgs> CallDisconnected;


CallControlService: Implementation of above interface

using System;

namespace CallControlServices

 public class CallControlService : ICallControlService
  public void RaiseCallCreatedEvent(string callId,Guid instanceId)
   if (CallCreated != null)
    CallEventArgs e = new CallEventArgs(instanceId, callId);
    CallCreated(this, e);

  public void RaiseCallDialingOutEvent(string callId, Guid instanceId)
    if (CallDialingOut != null)
     CallEventArgs e = new CallEventArgs(instanceId, callId);
     CallDialingOut(this, e);

  public void RaiseCallOfferingEvent(string callId, Guid instanceId)
   if (CallOffering != null)
    CallEventArgs e = new CallEventArgs(instanceId, callId);
    CallOffering(this, e);

  public void RaiseCallConnectedEvent(string callId, Guid instanceId)
   if (CallConnected != null) 
    CallEventArgs e = new CallEventArgs(instanceId, callId);
    CallConnected(this, e);

  public void RaiseCallOnHoldEvent(string callId, Guid instanceId)
   if (CallOnHold != null)
    CallEventArgs e = new CallEventArgs(instanceId, callId);
    CallOnHold(this, e);

  public void RaiseCallDisconnectedEvent(string callId, Guid instanceId)
   if (CallDisconnected != null)
    CallEventArgs e = new CallEventArgs(instanceId, callId);
    CallDisconnected(this, e);

  public event EventHandler<CallEventArgs> CallCreated;
  public event EventHandler<CallEventArgs> CallDialingOut;
  public event EventHandler<CallEventArgs> CallOffering;
  public event EventHandler<CallEventArgs> CallConnected;
  public event EventHandler<CallEventArgs> CallOnHold;
  public event EventHandler<CallEventArgs> CallDisconnected;

Associate an Event to a workflow activity

We now know something about the workflow, state, and activity. We have also defined the CallControlService interface and its implementation. Now, we will see how to associate an external event defined above with the workflow. This event will cause the workflow state to be transitioned to another state. This is really very simple! The Workflow Visual Studio designer provides a facility to go to each state/activity and define their properties. As shown below, the 'handleCallCreated' subactivity is defined as EventName = CallCreated and InterfaceType = "CallControlServices.ICallControlService".

Screenshot - ActivityEventAssoc.jpg


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
India India
Hiren Suchak is a Technical Lead and works for a software product development firm PROTEANS SOFTWARE SOLUTIONS LTD.( Hiren specializes in creating distributed client server based products using .net as a core technology. Hiren has worked in Visual C++, c#, Win32, .NET, Sockets, Remoting. Hiren cherishes trekking into Himalayas and enjoys all creativity. Hiren feels that desinging a good product is similar to playing a piece of music or drawing the canvas with paint brush. Hiren can be reached at

You may also be interested in...


Comments and Discussions

General[Message Deleted] Pin
it.ragester28-Mar-09 5:38
memberit.ragester28-Mar-09 5:38 
GeneralTAPI Pin
DR Delphi30-Aug-08 11:05
memberDR Delphi30-Aug-08 11:05 
General[Message Removed] Pin
immetoz4-Oct-08 15:11
memberimmetoz4-Oct-08 15:11 
Questionimplementing workflow foundation in a web based library circulation system using visual studion 2005 Pin
sohair zaki17-Jul-08 17:30
membersohair zaki17-Jul-08 17:30 
AnswerRe: implementing workflow foundation in a web based library circulation system using visual studion 2005 Pin
Amee_me18-Jul-08 2:36
memberAmee_me18-Jul-08 2:36 
QuestionHow scalable? Pin
Keith Vinson1-May-07 5:10
memberKeith Vinson1-May-07 5:10 
AnswerRe: How scalable? Pin
HirenSuchak2-May-07 1:34
memberHirenSuchak2-May-07 1:34 
GeneralWorkflow vs. State Machine Pin
Marc Clifton30-Apr-07 1:27
protectorMarc Clifton30-Apr-07 1:27 
GeneralRe: Workflow vs. State Machine Pin
element1430-Apr-07 3:00
memberelement1430-Apr-07 3:00 
GeneralRe: Workflow vs. State Machine Pin
HirenSuchak2-May-07 1:43
memberHirenSuchak2-May-07 1:43 
QuestionWorkflow : Adding UserControls to form Pin
Deepak D M10-Sep-07 23:22
memberDeepak D M10-Sep-07 23:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171018.2 | Last Updated 29 Apr 2007
Article Copyright 2007 by HirenSuchak
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid