Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
1 out of 2 rated this helpful - Rate this topic

Client Application Connection Code Sample

Office 2007

The Client Application Connection code sample shows how you can use Microsoft Office Live Small Business Web services to connect your client-side application to Office Live Small Business data.

This code takes advantage of the Office Live Small Business Discovery Web service, Windows Live ID Client, and the authentication services provided in the Microsoft System.Net namespace. You can provide access to an Office Live Small Business account from your application without requesting additional credential information by using a combination of these services.

As an example of accessing Office Live Small Business data after authentication, the Client Application Connection sample includes code that connects to an Office Live Small Business server with the user's Windows Live ID credentials to list all documents in one of the user's Office Live Small Business document libraries.

Download the Sample

Client Application Connection is provided as sample code. You can copy sections of this code or duplicate them in your application to help you provide authenticated connections.

To download the Client Application Connection code sample:

  1. Go to the MSDN Code Gallery.

  2. Download the WinZip file.

  3. Extract the files.

Authenticate your Client Application Connection

Microsoft Windows Live ID for client applications enables your application to access Windows Live ID sites and services, including Office Live Small Business, by using a customized authentication ticket.

The following steps demonstrate how you can authenticate a user who is logged on to an Office Live Small Business account from your client application to allow access to Office Live Small Business data.

Step 1. Authenticate the user's Windows Live ID account.

This sample uses the IdentityManager class of Windows Live ID to create an Identity object for the current user. Then it uses the Authenticate method of this class to authenticate the user’s Windows Live ID account.

IdentityManager identityManager;
identityManager = IdentityManager.CreateInstance(applicationId, 
                  applicationName);
Identity identity = identityManager.CreateIdentity();
if (!identity.Authenticate())
{
     throw new ApplicationException("Unable to authenticate the 
                         user’s Windows Live ID account.");
}

Step 2. Obtain the Office Live Small Business settings to generate a Windows Live ID authentication ticket.

The Client Application Connection code takes advantage of the Office Live Small Business Discovery Web service to discover the appropriate Windows Live ID settings. First, it accesses the Discovery Web service.

Discovery discoSvc = new Discovery();
discoSvc.Url = "https://apis.officelive.com/discoverywebsvc/discovery.asmx";

Next, it obtains the Windows Live ID settings for the Office Live Small Business Web service.

LiveIDSettings settings = discoSvc.GetLiveIDSettings();

Step 3. Request the user's current Windows Live ID authentication ticket for the Office Live Small Business Web service.

You can use the Windows Live ID GetTicket method to obtain the user’s authentication ticket information for the Office Live Small Business Web service.

string ticket = identity.GetTicket(settings.SiteName, settings.Policy, false);

Step 4. Authenticate the user for Office Live Small Business Web requests.

The class WindowsLiveAuthenticationModule, included in this sample code, handles Windows Live ID authentication for Office Live Small Business Web requests. This module implements an IAuthenticationModule interface from the Microsoft System.Net namespace.

This sample code then creates and registers a new authentication module by using the Register method of the AuthenticationManager class in the Microsoft System.Net namespace, passing the ticket obtained in step 3.

WindowsLiveAuthenticationModule authModule;
authModule = new WindowsLiveAuthenticationModule(ticket);
        AuthenticationManager.Register(authModule);

Authenticate is the core method for the Client Application Connection sample custom authentication. The following are details of the actual process that triggers the Authenticate method:

  1. When an Internet resource requests authentication, the System.Net WebRequest.GetResponse method calls the AuthenticationManager.Authenticate method.

  2. The AuthenticationManager.Authenticate method calls each registered authentication module to find the first module that can respond to the authentication request.

  3. When a module responds, an Authorization object is returned to the Web request.

This Authorization object is the key required to unlock the user's Office Live Small Business data.

Access Microsoft Office Live Small Business data

The example in this code is designed to print the names of the documents in the user’s Office Live Small Business document library if the user is authenticated.

You can use methods of the Discovery class in the Discovery Web service to determine which accounts are associated with the authenticated user and find a document library included in those accounts. The GetSubscriptions method enables the sample to find an Office Live Small Business account that the user owns. The GetResources method returns a list of resources, including document libraries, in the account. The code in this sample selects the first document library it finds.

The calls to the methods of the Discovery class invoke the WindowsLiveAuthenticationModule to authenticate this Office Live Small Business Web request:

discoSvc.UserAgent = discoSvc.UserAgent + ";" + WindowsLiveAuthenticationModule.WindowsLiveClientHeader;
discoSvc.Credentials = new NetworkCredential();

To access Windows Live ID sites and services such as Office Live Small Business, you must find the URL for the Web Service Description Language (WSDL) file that describes the service. The service that is used in this example is the SharePoint Lists Web service. In addition to adding this service as a Web reference, this example constructs a URL for it.

string listServiceUrl = userDocumentLibraryUrl + 
                        SharepointServicesPrefix  + "Lists.asmx";

It then connects to the Lists Web service for the user’s document library.

Lists listsWebService = new Lists();
listsWebService.Url = listServiceUrl;

Next, it invokes a WindowsLiveAuthenticationModule to authenticate this Office Live Small Business Web request.

listsWebService.UserAgent = listsWebService.UserAgent + ";" + 
          WindowsLiveAuthenticationModule.WindowsLiveClientHeader;
listsWebService.Credentials = new NetworkCredential();

The example then uses the Lists Web service to access and print the titles of all documents contained in the user’s document library.

See Also

Community Additions

Show:
© 2014 Microsoft. All rights reserved.