LCS使用RTC API 发送IM消息的WebService

微软LCS 2005 With SP1 发布也有一段时间了。 1。准备工作:安装RTC Client API 2:编写Lib 3:编写WebService

微软LCS 2005 With SP1 发布也有一段时间了。

1。准备工作:安装RTC Client API
        http://msdn.microsoft.com/downloads/list/clientapi.asp

 

 

Microsoft Windows Real-Time Communications Client API SDK v1.3
The Microsoft Windows Real-Time Communications Software Development Kit 1.3 provides information, samples, and tools regarding the additional features of the Real-Time Communications 1.3 API. Additional features include: enhanced multiple points of presence support, support for Microsoft Office Live Communications Server 2005, additional client security options, and marshalling support.

   
 

Microsoft Real-time Communications Client Software Development Kit (SDK) v1.2
The Microsoft Real-time Communications Client SDK provides documentation, sample code and other tools that allow developers to build real-time communication applications, or integrate real-time communication functionality into existing applications.
Note: To execute samples or applications upon any development or test machine, install the SDK and then run RTCAPISETUP.EXE to install the Microsoft Real-time Communications Client API binaries. This executable can be found within the "Installation" sub-directory.

   

重要:请安装同时1.2和1.3 ,安装完下载后的MSI包之后,而且要运行
    :\Program Files\RTC Client API v1.2 SDK\INSTALLATION\RtcApiSetup.exe
    :\Program Files\RTC Client API v1.3 SDK\INSTALLATION\RtcApiSetup.exe
    :\Program Files\RTC Client API v1.3 SDK\INSTALLATION\RtcSxSPolicies.msi
   以上3个全部要安装,不是说安装1.3就不需要安装1.2了,而且要按照这个顺序,否则可能不能成功。
最好重新启动电脑吧,(把WebService发布到服务器时候记得也要在服务器上面安装哦)

2:编写Lib

None.gifusing System;
None.gifusing System.Collections.Generic;
None.gifusing System.Text;
None.gif
None.gifnamespace CMS.LCSLib
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    public class RTCClass
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{            
InBlock.gif
InBlock.gif        private static void  createEnableProfile(RTCCORELib.RTCClient objRTCClient, string account, string password, string uri, string addr, string domain)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string s = "";
ExpandedSubBlockStart.gifContractedSubBlock.gif            s += "<provision key=\"dot.gif{566E246F-9978-4434-83BF-3E47BCCFF466}\" name=\"" + domain + "\">";
InBlock.gif            s += "<user account=\"" + account + "\" password=\"" + password + "\" uri=\"" + uri + "\" />";
InBlock.gif            s += "<sipsrv addr=\"" + addr + "\" protocol=\"tcp\" role=\"proxy\">";
InBlock.gif            s += "<session party=\"first\" type=\"pc2pc\" />";
InBlock.gif            s += "<session party=\"first\" type=\"pc2ph\" />";
InBlock.gif            s += "<session party=\"first\" type=\"im\" />";
InBlock.gif            s += "</sipsrv>";
InBlock.gif            s += "<sipsrv addr=\"" + addr + "\" protocol=\"tcp\" role=\"registrar\" />";
InBlock.gif            s += "</provision>";
InBlock.gif            
InBlock.gif            RTCCORELib.IRTCProfile2 objProfile;//
InBlock.gif            RTCCORELib.IRTCClientProvisioning2 objProvisioning;//
InBlock.gif
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                objProvisioning = (RTCCORELib.IRTCClientProvisioning2)objRTCClient;
InBlock.gif
InBlock.gif                objProfile = (RTCCORELib.IRTCProfile2)objProvisioning.CreateProfile(s);
InBlock.gif
InBlock.gif                //EnableProfile
InBlock.gif                objProvisioning.EnableProfile(objProfile, 0xF);
InBlock.gif                //g_objProvisioning.EnableProfileEx(g_objProfile, 0x0000000F, 0x0000000F);
ExpandedSubBlockEnd.gif            }
InBlock.gif            catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                System.Diagnostics.EventLog.WriteEntry("LCSClass", ex.ToString());
ExpandedSubBlockEnd.gif            }
InBlock.gif            return ;
InBlock.gif
ExpandedSubBlockEnd.gif        }
InBlock.gif
ExpandedSubBlockStart.gifInBlock.gif        public static void SendMessage(string strDestURI)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            string account = @"tianchi\test";
InBlock.gif            string password = "test";
InBlock.gif            string uri = "sip:test@tianchi.local";
InBlock.gif            string addr = "cms-biztalk.tianchi.local:5060";
InBlock.gif            string domain = "tianchi.local";
InBlock.gif            string strMsgHeader = null;
InBlock.gif            string strMsg = "test from webservice";
InBlock.gif            int lCookie = 0;
InBlock.gif            string strDestName = null;

InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{

InBlock.gif                  SendMessage(account, password, uri, addr, domain,
InBlock.gif                       strMsgHeader, strMsg, lCookie, strDestURI, strDestName);
}
                  catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                System.Diagnostics.EventLog.WriteEntry("LCSClass", ex.ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            return;
ExpandedSubBlockEnd.gif        }
InBlock.gif
InBlock.gif        public static void SendMessage(string account, string password, string uri, string addr, string domain,
InBlock.gif            string strMsgHeader, string strMsg, int lCookie, string strDestURI, string strDestName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
InBlock.gif            try
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                RTCCORELib.RTCClient objRTCClient;//            
InBlock.gif                RTCCORELib.IRTCSession objSession;
InBlock.gif                //RTCCORELib.IRTCParticipant g_objParticipant;
InBlock.gif
InBlock.gif                //'RTCClient needs to be initialized before any other method can be called on it.
InBlock.gif                objRTCClient = new RTCCORELib.RTCClient();
InBlock.gif                objRTCClient.Initialize();
InBlock.gif
InBlock.gif                //createProfile & EnableProfile
InBlock.gif                createEnableProfile(objRTCClient, account, password, uri, addr, domain);
InBlock.gif
InBlock.gif                //'Create an IM session.
InBlock.gif                objSession = objRTCClient.CreateSession(RTCCORELib.RTC_SESSION_TYPE.RTCST_MULTIPARTY_IM, null, null, 0);
InBlock.gif
InBlock.gif                //'Add a participant to the IM session.
InBlock.gif                //g_objParticipant = g_objSession.AddParticipant(strDestURI, strDestName);
InBlock.gif                objSession.AddParticipant(strDestURI, strDestName);
InBlock.gif
InBlock.gif                //'Send a message.
InBlock.gif                objSession.SendMessage(strMsgHeader, strMsg, lCookie);
InBlock.gif                //g_objSession.SendMessage(null, strMsg, 0);
ExpandedSubBlockEnd.gif            }
InBlock.gif            catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
InBlock.gif                System.Diagnostics.EventLog.WriteEntry("LCSClass", ex.ToString());
ExpandedSubBlockEnd.gif            }
ExpandedSubBlockEnd.gif        }
ExpandedSubBlockEnd.gif    }
ExpandedBlockEnd.gif}
None.gif

3:编写WebService
None.gifusing System;
None.gifusing System.Web;
None.gifusing System.Web.Services;
None.gifusing System.Web.Services.Protocols;
None.gif
None.gif[WebService(Namespace = "http://tempuri.org/")]
None.gif[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
None.gifpublic class RTCClass : System.Web.Services.WebService
ExpandedBlockStart.gifContractedBlock.gifdot.gif{
InBlock.gif    public RTCClass()
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif
InBlock.gif        //Uncomment the following line if using designed components 
InBlock.gif        //InitializeComponent(); 
ExpandedSubBlockEnd.gif    }
InBlock.gif
InBlock.gif    [WebMethod]
InBlock.gif    public void SendMessage(string account, string password, string uri, string addr, string domain,
InBlock.gif            string strMsgHeader, string strMsg, int lCookie, string strDestURI, string strDestName)
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
InBlock.gif        CMS.LCSLib.RTCClass.SendMessage( account,  password,  uri,  addr,  domain,
InBlock.gif             strMsgHeader,  strMsg,  lCookie,  strDestURI,  strDestName);
InBlock.gif        return ;
ExpandedSubBlockEnd.gif    }
InBlock.gifContractedSubBlock.gif    /**//// <summary>
InBlock.gif    /// 发送一个测试消息给某个用户
InBlock.gif    /// </summary>
ExpandedSubBlockEnd.gif    /// <param name="strDestURI">格式:sip:cleo@tianchi.local</param>
InBlock.gif    [WebMethod]
InBlock.gif    public void SendMessageTest(string strDestURI)
ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{      
InBlock.gif        CMS.LCSLib.RTCClass.SendMessage( strDestURI);
InBlock.gif        return;
ExpandedSubBlockEnd.gif    }
InBlock.gif    
ExpandedBlockEnd.gif}
None.gif

关于RTCCORELib.dll 引用问题
++++++++++++++++++++++++++++++++++++++++
在项目里面引用DLL的时候,
路径可能是:C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Networking.RtcDll_6595b64144ccf1df_5.2.2.1_x-ww_d6bd8b93\RTCCORELib.dll
你在\WINDOWS\WinSxS\x86_Microsoft.Windows.Networking.RtcDll_XXXXX之类的目录里面找就可以,
你也可以搜索RTCCORELib.dll

注意在SDK安装的时候,要关闭其它程序,尤其是Messager之类的,否则可能会造成找不到RTCCORELib.dll