| OL Blog's profileThe Microsoft Office Liv...BlogLists | Help |
|
March 28 The Microsoft Office Live Client Application Connection code sampleThe Microsoft Office Live Developer Platform Team has created some sample code to show how you can use Microsoft Office Live Web services to connect your client-side application to Microsoft Office Live data. This code sample takes advantage of the Microsoft Office Live Discovery Web service, Windows Live ID for client applications , and the authentication services provided in the Microsoft System.Net namespace. Once you know how to combine these services, you can provide access to data in an Office Live subscription from your application without requesting additional credential information. As an example of accessing Microsoft Office Live data after authentication, the Client Application Connection sample includes code that connects to a Microsoft Office Live server with the user's Windows Live ID credentials to list all documents in one of the user's Microsoft Office Live document libraries. Download the sampleClient Application Connection is provided as sample code. You can copy snippets of this code or duplicate them in your application to help you provide authenticated connections. To download the .exe file, go to the Microsoft Download Center. · Click the .exe file to install the Client Application Connection files to the following location: C:\Microsoft Office Live Developer Resources\Client Application Connection Sample Authenticate your Client Application ConnectionWith Windows Live ID for client applications, your application can access Windows Live ID sites and services, including Microsoft Office Live, using a customized authentication ticket. Let’s say that Dan Park signs in to his Microsoft Office Live account, and then opens your client application. The following steps demonstrate how you can authenticate Dan from your client application to allow access to Microsoft Office Live data. Step 1. Authenticate Dan’s Windows Live ID account.This sample uses the IdentityManager class of Windows Live ID to create an Identity object for the current user and then 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. Get the Microsoft Office Live settings needed to generate a Windows Live ID authentication ticket.The Client Application Connection code takes advantage of the Microsoft Office Live Discovery Web service to quickly discover the appropriate 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 gets the Windows Live ID settings for the Microsoft Office Live service.
LiveIDSettings settings = discoSvc.GetLiveIDSettings(); Step 3. Request Dan’s current Windows Live ID authentication ticket for the Microsoft Office Live service.You can use Windows Live ID’s GetTicket method to get the user’s authentication ticket information for the Microsoft Office Live service. string ticket = identity.GetTicket(settings.SiteName, settings.Policy, false);Step 4. Authenticate Dan for Microsoft Office Live Web requests.The class WindowsLiveAuthenticationModule, included in this sample code, handles Windows Live ID authentication for Microsoft Office Live 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 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 is the key you need to unlock Dan’s Microsoft Office Live data. Access Microsoft Office Live data
The example in this code is designed to print the names of the documents in the user’s Microsoft Office Live document library if the user is authenticated. You can use methods of the Discovery class in the Discovery Web service to determine the subscriptions that are associated with Dan Park and find a document library included in those subscriptions. The GetSubscriptions method allows you to identify a Microsoft Office Live subscription that Dan owns. The GetResources method returns a list of resources, including document libraries, in the subscription. The code in this example selects the first document library it finds. The calls to the methods of the Discovery class invoke a WindowsLiveAuthenticationModule to authenticate this Microsoft Office Live Web request: discoSvc.UserAgent = discoSvc.UserAgent + ";" + WindowsLiveAuthenticationModule.WindowsLiveClientHeader; discoSvc.Credentials = new NetworkCredential(); To access Windows Live ID sites and services, including Microsoft Office Live, you must find the URL of the Web Service Description Language (WSDL) file that describes the service. The service being used in this example is the SharePoint Lists Web service. In addition to adding this service as a Web reference, the example constructs a URL for it. string listServiceUrl = userDocumentLibraryUrl + SharepointServicesPrefix + "Lists.asmx";
It then connects to the Lists Web service for Dan’s document library.
Lists listsWebService = new Lists(); listsWebService.Url = listServiceUrl;
Next, it invokes a WindowsLiveAuthenticationModule to authenticate this Microsoft Office Live 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 Dan’s document library. Connect your client applicationsThe Web services provided by Microsoft Office Live, Windows Live ID for client applications, and the Microsoft System.Net namespace combine to provide easy access to the information you need in order to provide a connection between a client application and Microsoft Office Live data. You can use the code in this sample to help incorporate this functionality in your application.
The Office Live Developer Platform team Comments (3)
OL Blog
has turned off comments on this page.
TrackbacksThe trackback URL for this entry is: http://officeliveblog.spaces.live.com/blog/cns!7A0018FE70A946FB!626.trak Weblogs that reference this entry
|
|
|