Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / Windows Forms
Article

Call Control Implmentation Using the Windows Workflow Foundation

Rate me:
Please Sign up or sign in to vote.
3.67/5 (5 votes)
28 Apr 2007CPOL2 min read 68.7K   993   44   11
A call control implmentation using the State machine Workflow.

Screenshot - newCall.jpg

Introduction

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.

Background

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.

C#
using System;
using System.Workflow.Activities;

namespace CallControlServices
{

 [ExternalDataExchange]
 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

C#
using System;

namespace CallControlServices
{

 [Serializable]
 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

License

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


Written By
Web Developer
India India
Hiren Suchak is a Technical Lead and works for a software product development firm PROTEANS SOFTWARE SOLUTIONS LTD.(www.proteans.com). 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 hirensuchak@gmail.com

Comments and Discussions

 
General[Message Deleted] Pin
it.ragester28-Mar-09 5:38
it.ragester28-Mar-09 5:38 
GeneralTAPI Pin
DR Delphi30-Aug-08 11:05
DR Delphi30-Aug-08 11:05 
General[Message Removed] Pin
immetoz4-Oct-08 15:11
immetoz4-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
sohair 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
Amee_me18-Jul-08 2:36 
You can use sequencial workflow. There are so many examples available on the net. I will send you some of them. Webservice is separate than workflow. You can use web services from workflow as an external call. Right now I am very busy setting up my personal things. I will give more information once I will get some time.
QuestionHow scalable? Pin
Keith Vinson1-May-07 5:10
Keith Vinson1-May-07 5:10 
AnswerRe: How scalable? Pin
HirenSuchak2-May-07 1:34
HirenSuchak2-May-07 1:34 
GeneralWorkflow vs. State Machine Pin
Marc Clifton30-Apr-07 1:27
mvaMarc Clifton30-Apr-07 1:27 
GeneralRe: Workflow vs. State Machine Pin
element1430-Apr-07 3:00
element1430-Apr-07 3:00 
GeneralRe: Workflow vs. State Machine Pin
HirenSuchak2-May-07 1:43
HirenSuchak2-May-07 1:43 
QuestionWorkflow : Adding UserControls to form Pin
Deepak D M10-Sep-07 23:22
Deepak 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.