为 Web 应用程序指定移动信息服务
上次修改时间: 2010年1月13日
适用范围: SharePoint Foundation 2010
本主题介绍如何以编程方式向 Web 应用程序分配短信服务帐户。
为 Web 应用程序创建 MSP 帐户
每个 SharePoint Foundation Web 应用程序(包括管理中心 Web 应用程序)都可以有一个短信服务提供商 (MSP) 帐户。通常情况下,这些帐户由服务器场管理员在管理中心应用程序的"应用程序管理"部分设置。不过,您可以通过编程创建一个帐户并将其分配给 Web 应用程序。首先,调用不需要 SPMobileMessageServiceProvider 参数的 SPMobileMessagingAccount() 构造函数。然后调用 UpdateSmsAccount(SPMobileMessagingAccount) 方法以将该帐户分配给 Web 应用程序。在以下代码段中,webApp 是对 SPWebApplication 对象的引用。(有关如何获取对此类对象的引用的信息,请参阅获取对网站、Web 应用程序和其他关键对象的引用。)该代码段假设文件具有 Microsoft.SharePoint 和 System.Security 命名空间的 using 语句。请注意,服务的 URL 必须以"https"开头;即,它必须是安全套接字层 (SSL) URL。还请注意,对 UpdateSmsAccount(SPMobileMessagingAccount) 的调用会作为匿名委派的一部分传递给 RunWithElevatedPrivileges(SPSecurity.CodeToRunElevated) 方法。
SecureString password = new SecureString();
password.AppendChar('a');
password.AppendChar('Z');
password.AppendChar('3');
password.AppendChar('&');
SPMobileMessagingAccount account =
new SPMobileMessagingAccount("Contoso Messaging",
"https://contoso.com/services/mobilemessages",
"BobG",
password);
SPSecurity.RunWithElevatedPrivileges(delegate() {webApp.UpdateSmsAccount(account);
webApp.Update();});
Dim password As New SecureString()
password.AppendChar("a")
password.AppendChar("Z")
password.AppendChar("3")
password.AppendChar("&")
Dim account As New SPMobileMessagingAccount("Contoso Messaging", "https://contoso.com/services/mobilemessages", "BobG", password)
SPSecurity.RunWithElevatedPrivileges(Sub()
webApp.UpdateSmsAccount(account)
webApp.Update()
End Sub)
为 Web 应用程序分配 MSP 帐户后,您的代码即可将 OutboundSmsServiceAccount 属性用作对 Web 应用程序的帐户对象的引用。