Friday, May 30, 2008

Subscriptions in UCMA Part 1: Roaming Contacts

Looking at the UCMA 1.0 SDK stated that it is possible to use subscriptions. The only thing that is missing is how to implement them? What do we need to send? What do we get back?

For this information you have to dig deep into the protocols.
Recently Microsoft published preliminary versions of these protocols. You can find them here: Office Protocol Documents. It's almost 90 Mb in PDF documents :-(.

For me the most important subscriptions are at the moment: "Roaming Contacts", "Self", and the most important one "presence".

This part I'll focus on Roaming Contacts. This subscription returns all the groups and contacts you are subscribed to.

First we have to create a class that implements the ISipSubscriptionProcessor. Next to setting the message and the SignalingHeaders, the main thing for this class is handling the notifications.

public class RoamingContactsSubscription : ISipSubscriptionProcessor
{
void ISipSubscriptionProcessor.GetExtensionHeaders(SipSubscription.RequestType requestType, out IEnumerable<SignalingHeader> extensionHeaders)
{
extensionHeaders = null;
}

void ISipSubscriptionProcessor.GetMessageBody(SipSubscription.RequestType requestType, out ContentType contentType, out byte[] messageBody)
{
contentType = null;
messageBody = new Byte[0];
}

void ISipSubscriptionProcessor.ProcessErrorResponse(SipResponseData message)
{
//Not implemented
}

void ISipSubscriptionProcessor.SubscriptionStateChanged(SubscriptionStateChangedEventArgs e)
{
//Not implemented
}
public void ProcessNotification(SipMessageData message)
{
String s = message.GetMessageBodyString();
ContentType contentType = message.ContentType;

// TODO; Do somthing with the notification message!!!
}

}



Next we have to subscribe. For this code I already registered an endpoint. The event package name is : "vnd-microsoft-roaming-contacts"




public void SubscribeRoamingContacts()
{
RoamingContactsSubscription myRCSubscription = new RoamingContactsSubscription();
SipEndpoint myEndpoint = _endPoint;
RealTimeAddress RCAddress = new RealTimeAddress(_endPoint.Uri);
SipSubscription mySubScription = new SipSubscription(myEndpoint, RCAddress, "vnd-microsoft-roaming-contacts", myRCSubscription);
mySubScription.BeginSubscribe(SubscribeRoamingContactsCallback, mySubScription);
}



 




private void SubscribeRoamingSelfCallback(IAsyncResult asyncResult)
{
SipSubscription mySubscription = asyncResult.AsyncState as SipSubscription;
try
{
mySubscription.EndSubscribe(asyncResult);
}
catch (PublishSubscribeException)
{
//TODO
}

catch (RealTimeException)
{
//TODO
}
}



That is actually all. Here is a sample of the Notification message:




<contactList deltaNum="4">
<group id="1" name="~" externalURI="" />
<contact uri="Joachim.Farla@e-office.com" name="" groups="1" subscribed="true" externalURI="" />
<contact uri="Marc.Wetters@e-office.com" name="" groups="1" subscribed="true" externalURI="" />
</contactList>



 



Next Part will be self subscribe.



For more information/questions/remarks please contact me sip:marc.wetters@e-office.com

No comments:

working at e-office