Live Communications Server Application API (1)
Posted on 2006-01-17 09:43 snowolf 閱讀(436) 評論(0) 編輯 收藏 所屬分類: 其他Live Communications Server Application API
發布時間:2005 年 6 月
Microsoft SIP Processing Language(MSPL)、Microsoft.Rtc.Sip命名空間、application manifests 和為LCS構建SIP應用程序的資料。
Note The Live Communications Server Application API currently does not support SIP dialogs and UAC server behaviors. Future versions of the API will add support for these features.
1. Application manifests
The application manifest is an XML document that describes a Live Communications Server application to the server on which it is running. This document is presented to the server when the application registers with Live Communications Server through the Microsoft.Rtc.Sip.ServerAgent managed class.
Application manifests由以下三部分組成:
1.1.1 <alias:applicationManifest>標簽。
在這個標簽內裝入應用程序屬性(Application attributes)和消息過濾腳本(MSPL),可以為"alias"定義一個別名,微軟建議使用默認別名"ls"。
1.1.2 A set of application attributes that defines key properties of the application, such as the SIP message types to filter and whether it is script-only.
1.1.3 用MSPL語言寫的消息過濾腳本。
在CDATA element里被附加上<alias:splScript>標簽。
1.2 Application manifests部屬:
這個Application manifests文件,一次建立后,可以和裝配件(assembly)里的resource一樣,植入應用程序內部,或者像一個外部文件一樣存在。
1.2.1 植入assembly內部:
用Microsoft.Rtc.Sip命名空間的ApplicationManifest類,在新生成的 ApplicationManifest對象里用Compile方法對它進行編譯。樣里代碼如下:



















編譯成功后,這個編譯過的Application manifests部屬到代理服務器上,
1.2.2 外部文件格式:
下面是一個僅有SIP INVITE and MESSAGE請求的基本的application manifest:






















Application Attibutes在消息過濾腳本的前面,在<lc:applicationManifest>標簽的后面,包含詳細的描述LCS應用程序的數據。例如下面所示:









其中,xmlns屬性指定了用那個版本的LCS來運行應用程序,如果是LCS2003就采用下面的方式:
xmlns:lc=http://schemas.microsoft.com/rtc/2003/05
1.3.1

說明:為應用程序指定默認代理行為。
如果是true,服務器自動代理任意消息,應用程序不依據句柄執行。如果是false,消息被拋出,應用程序結束,同時,一方將不會收到它。
1.3.2

說明:當部署時,指定應用程序不含托管代碼的成分。
1.3.3

說明:指定應用程序通過服務器的那些請求。
有下列methodNames
REGISTER
SUBSCRIBE
NOTIFY
BENOTIFY
ACK
BYE
INVITE
OPTIONS
MESSAGE
SERVICE
INFO
REFER
OTHER
1.3.4

說明:定義應用程序通過服務器響應那個類別。
類別如下:
1XX
2XX
3XX
4XX
5XX
6XX
1.3.5




說明:Name屬性指引用的text文件名稱,必須是有效的MSPL。Path屬性是這個文件的決對路徑,如果是相對的,它必須是相對于運行RTCSRV.exe的路徑。
1.3.6

用這個標簽可以指定一個或多個列節點。
2. Microsoft SIP Processing Language
MSPL是用來過濾或路由SIP消息的腳本語言,像大家知道的"message filters",這個腳本是植入到application manifests里的LCS應用程序中。
MSPL不支持:
Explicit (declarative) data types
Type casting
Pointers
Declarations (other than basic function declarations, as detailed below)
Arithmetic operations
Iteration statements
Preprocessor statements
Attributes
Static or global variables (state is not maintained across script invocations)
2.1.1 Function Invocation
一個函數在MSPL里是唯一的,在MSPL里函數用如下語法格式來定義:





所有的函數定義必須在消息過濾腳本的開始處,在過濾腳本之前。一個函數能有零個或更多的參數。為了防止無意中的循環,遞歸函數的調用是不允許的。互相的遞歸調用calls-calls模式也是不允許的。例如,如果函數1調用函數2,然后調用函數3,函數3不能調用1或2的任意一個。返回值類型是implicitly defined的,更確切的說,這個類型是傳遞的返回聲明的值決定的。參數也是implicitly defined的。函數不能返回collections,它支持的的返回類型有strings,bools,integers和floats.
下面的函數示例過濾了一個特殊的string,如果這個string被找到返回true,否則,返回false.







在SIP消息處理過程中foreach允許腳本編寫者比較句柄collections,例如contact header collections和 endpoint collections。下面示例演示了foreach loop的語法構成。







Break 的用法和C#中switch/case里的用法相同
Null關鍵字,腳本語法能添加一個null關鍵字,與empty string ("")不同,empty string是不能建立的。有下列函數將返回一個null來表明值沒有找到或者錯誤。
" GetDisplayName
" GetHostName
" GetParameterValue
" GetScheme
" GetUri
" GetUriParameter
" GetUserName
" GetUserAtHost
" GetXMLAttr
" QueryHomeServer
另外,Message.Stamp 和 Message.StampPool也返回null.
要:本文檔將介紹從最初建造一個application manifest到最終安裝和管理SIP application的詳細過程,并提供示例代碼,以演示開發擴展LCS應用的具體方法。
Live Communications Server Application API應用
1 在新的服務器布局里開發應用程序
Live Communications Server 2005支持新的服務器角色,包括:Standard Edition, Enterprise Edition, Enterprise Edition Pool, Enterprise Edition Back End Storage, Archiving Service, Director, Proxy, and Access Proxy。第三方應用程序能配置到上述任意或全部服務器上,以滿足想得到的功能性。理解每個新的服務器角色的功能是開發和設計應用程序的要點。
2 建立一個Application Manifest
以LCS默認核心消息過濾腳本為例(此腳本原始位置:..\Program Files\Microsoft LC 2005\Server\ routing.am):
這個MSPL腳本過濾引入的SIP消息,并且以端點ID(EDID)、可用性合計、活動性數值和AgeOfPresence數值為基礎,嘗試為每一個消息選擇出最好的端點。端點沒有注冊存在或者可用性合計小于100的將不被考慮。
示例代碼




















































































3 為Live Communications Server 創建一個SIP應用程序
3.1 Setting up a Server Agent
server agent是你的應用程序和LCS之間的公共點。它是用ServerAgent類定義的對象,由它通過LCS代表你的應用程序發送和接收消息。
配置一個 LCS Agent的第一步是建立一個application manifest并編譯。這個application manifest將要運行在服務器上并且通過消息過濾腳本僅接收你的應用程序感興趣的SIP消息。這個動作是通過執行你的應用程序的Main方法實現的。例如下面代碼:




































在實例化ServerAgent的時候提供ApplicationManifest對象,ServerAgent的構造函數會編譯這個Application Manifest.例如下面代碼。















應用程序必須從消息過濾中分配句柄信息,同時,還必須建立一個類和這個句柄的方法對應。例如下面代碼,如果你有一個call在你的消息過濾器里。
Dispatch("OnInviteReceived");
在你的定義的類上必須有一個相應的OnInviteReceived方法。
3.2 Processing Server Events
當Dispatch被腳本呼叫過,一個服務器事件便被觸發。
3.3 Handling Messages from the Live Communications Server
當LCS收到消息,application manifest必須有特定的轉發給相應得應用程序。
例如在application manifest中有下列代碼:




上述代碼功能是, 當LCS分配SIP消息類型為“MESSAGE”的消息給“OnMessageReceived”你的應用程序的事件句柄,定義事件句柄的代碼示例如下:

































參考文檔《Microsoft Office Live Communications Server 2005》