开发者

Publishing a custom presence message in OCS2007 R2 using UCMA 2.0 (visible in MOC)

I'm writing a UCMA 2.0 application which connects with a 'UserEndpoint' to OCS. I want to be able to set a custom presence message along with my availability!

I've run into some issues along the way and spent a lot of time Googling and tried out a few articles, the majority seem to be saying the same thing (including MS themselves):

Use XML to set the 'userState' activity to be custom and contain a message, then publish that in a custom category via the endpoint's 'LocalOwnerPresence.BeginPublishPresence' method.

I don't get any errors back from OCS when I do this (see the XML example below), but looking at the presence in Office Communicator (MOC) the user in question continues to appear offline. I have found that also publishing the 'machineState' means that we see some presence icon in MOC, but alas, I can't get the custom activity message working.

More reading sent me on wild goose chases, such as stored procs in the OCS DB that need to be run to allow this (sounded more like for adding brand new presence categories rather than just a custom message to an existing state). I'm kind of at the end of my tether after a day 'online'.

Any help or pointing out any gotchas would be appreciated! I've included a few of the sites I used when reading up on this:

Presence Intro: http://msdn.microsoft.com/en-us/library/dd253506(v=office.13).aspx

Publishing Presence: http://msdn.microsoft.com/en-us/library/dd253494(v=office.13).aspx

Presence + Custom messages: http://blogs.claritycon.com/blog/2009/03/04/how-to-publish-presence-using-ucma-v2-0-and-have-a-clever-communicator-status/

Machine state ideas: http://social.msdn.microsoft.com/Forums/en-US/ucmanagedsdk/thread/d3bd3569-66c0-4b52-86f0-900d2fb6d22e/

Presence Schema doc: http://msdn.microsoft.com/en-us/library/dd941536(v=office.13).aspx

Here's the XML (string) that I'm using in my code, on the fly I string.Format the placeholders with a custom message and an availability integer value ("test message" and 3500 for the sake of argument).

string userStateXmlFormat = "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" xml开发者_开发百科ns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" manual=\"true\" xsi:type=\"userState\">\n"
            + "<availability>{0}</availability>\n"
                + "<activity>\n" 
                   + "<custom xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\">{1}</custom>\n" 
                + "</activity>\n"
            + "</state>";

Here's the C# that does the formatting, and attempting to publish the presence:

var machineStateXml = string.Format(machineStateXmlFormat, 3500);
var userStateXml = string.Format(userStateXmlFormat, 3500, "Test Message");
var machineState = new CustomPresenceCategory("state", machineStateXml);
var userState = new CustomPresenceCategory("state", userStateXml);                
PresenceCategory[] categoriesToPublish = new PresenceCategory[] { machineState, userState };
this.Endpoint.LocalOwnerPresence.BeginPublishPresence(categoriesToPublish, this.PublishPresenceCompleted, null);

Hopefully I haven't left anything out, please comment if you think there's something missing!

Cheers Pete


OK, this is a little embarrassing as I have managed to solve it - but I think I can point some blame at MS:

It seems that you MUST specify the LCID (the culture info ID) on the custom message in order for MOC to pick it up, sadly the docs on MSDN seem to think that it's not required (maybe it's not, but for things to work right it is)

http://msdn.microsoft.com/en-us/library/dd941468(v=office.13).aspx

LCID (int): An integer representing the location ID. Optional

This means I have to add the custom message multiple times though for each potential locale that the recipients using MOC might be in, doesn't seem the best way to do things (see below for example).

string userStateXmlFormat = "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" manual=\"true\" xsi:type=\"userState\">\n"
  + "<availability>{0}</availability>\n"
  + "<activity>\n" 
    + "<custom LCID=\"1033\" xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\">{1}</custom>\n"
    + "<custom LCID=\"2057\" xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\">{1}</custom>\n" 
  + "</activity>\n"
+ "</state>";

Anyway, I hope this helps someone else who wanted a generic message for all cultures, maybe the links above are useful reading too if you want to create something similar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜