Share via


Redirecting a Signaling Session

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The following code example illustrates how to redirect an invitation to another party whose URI is "sip:jayanama@contoso.com".

// Forward the session to a particular user.
List<RealTimeAddress> sessionTargets = new List<RealTimeAddress>();
sessionTargets.Add( new RealTimeAddress ("sip:jayanama@contoso.com"));

session.TerminateWithRedirection(sessionTargets);

The preceding example uses the TerminateWithRedirection overload that takes a list of type RealTimeAddress as its argument. Another TerminateWithRedirection overload that takes a single RealTimeAddress can be also be used when the session is to be redirected to a single individual.

string userURI = "sip:jayanama@contoso.com";
session.TerminateWithRedirection(new RealTimeAddress(userURI));

When an invitation request is redirected, the application of the original inviter receives a Redirecting event, if the application has subscribed to the event. The application uses the event arguments to process the session redirection. There are four actions the application can take for handling the redirection. These actions are enumerated in the RedirectAction enumeration type. The application can choose one of the four actions by setting the Action property on the RedirectingEventArgs object (passed into the registered event handler for the Redirecting event). The following code excerpts show how an application can subscribe to the Redirecting event, and shows several alternative ways to implement a handler for this event.

// The original session initiating the INVITE request
SignalingSession session = ...;

// Redirect the session to some user.
session.Redirecting += this.OnRedirectingReceived;

In the following version, all targets are tried until a successful redirection occurs.

// Try all redirect targets until one of them succeeds
void OnRedirectingReceived( object sender, RedirectingEventArgs e )
{
    e.Action = RedirectAction.TryAll;
}

In the next version, the signaling session is redirected to a specific individual. The redirect occurs only if the list of URIs contain the URI specified here, and is allowed only for the specified URI and no other on the list.

// Try the redirect targets only if it is "sip:john@contoso.com"
void OnRedirectingReceived( object sender, RedirectingEventArgs e )
{
    string redirectingTarget = e.CurrentTarget.Uri;

    // Redirect only if the target is my address
    if( redirectingTarget == "sip:john@contoso.com")
    {
       e.Action = RedirectAction.TryThis;
    }

    else
    {
       // Skip this and go to the next redirect target
       e.Action = RedirectAction.SkipThis;
    }
}

The application can ignore redirection either by not subscribing to the Redirecting event or by assigning TryNone to the Action property. The following code example shows a version of the event handler that demonstrates the second option.

// Ignore any redirect requests
void OnRedirectingReceived( object sender, RedirectingEventArgs e )
{
    e.Action = RedirectAction.TryNone;
}

See Also

Concepts

Signaling Session