Assign a Mobile Message Service to a Web Application

SharePoint 2010

Last modified: January 13, 2010

Applies to: SharePoint Foundation 2010

This topic describes how you can programmatically assign a mobile messaging service account to a Web application.

Each SharePoint Foundation Web application, including the Central Administration Web application, can have an account with a mobile messaging service provider (MSP). Normally, these accounts are set by a farm administrator in the Application Management portion of the Central Administration application. However, you can programmatically create an account and assign it to a Web application. First, call a SPMobileMessagingAccount() constructor that does not require an SPMobileMessageServiceProvider parameter. Then call the UpdateSmsAccount(SPMobileMessagingAccount) method to assign the account to a Web application. In the following snippet, webApp is a reference to an SPWebApplication object. (See Getting References to Sites, Web Applications, and Other Key Objects for information on how to get a reference to such an object.) The snippet assumes that the file has using statements for Microsoft.SharePoint and System.Security Namespace. Note that the URL of the service must begin with "https"; that is, it must be a Secure Socket Layer (SSL) URL. Note also that the call to UpdateSmsAccount(SPMobileMessagingAccount) is passed as part of an anonymous delegate to the RunWithElevatedPrivileges(SPSecurity.CodeToRunElevated) method.

SecureString password = new SecureString();

SPMobileMessagingAccount account = 
    new SPMobileMessagingAccount("Contoso Messaging",

SPSecurity.RunWithElevatedPrivileges(delegate() {webApp.UpdateSmsAccount(account);

Once the Web application has been assigned an account with the MSP, your code can thereafter use the OutboundSmsServiceAccount property as a reference to the Web application’s account object.