connecting_a_silverlight_application_to_line-of-business_information

34
Connecting a Silverlight Application to Line-of-Business Information Using the Business Data Connectivity Services (BDC) in SharePoint Server Foundation 2010 Author Christoph Schuler, Technical Consultant, foursquared Consulting, [email protected] Summary The Microsoft SharePoint Server Foundation 2010 offers exciting new capabilities to integrate business data into SharePoint Server and Office-based business applications. This paper provides an introduction to how information from a Line-of-Business (LOB) system, such as SAP ERP, can be integrated into a SharePoint-based user experience, thus enabling the Information Worker to interact with business data in the browser, using standard, out-of-box SharePoint UI components or a rich, interactive Silverlight UI. . Microsoft – Collaboration Brief March, 2010

Upload: bobi2201

Post on 01-Jul-2015

50 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to

Line-of-Business Information

Using the Business Data Connectivity Services (BDC) in

SharePoint Server Foundation 2010

Author

Christoph Schuler, Technical Consultant, foursquared Consulting, [email protected]

Summary

The Microsoft SharePoint Server Foundation 2010 offers exciting new capabilities to integrate business data into SharePoint Server and Office-based business applications. This paper provides an introduction to how information from a Line-of-Business (LOB) system, such as SAP ERP, can be integrated into a SharePoint-based user experience, thus enabling the Information Worker to interact with business data in the browser, using standard, out-of-box SharePoint UI components or a rich, interactive Silverlight UI. .

Microsoft – Collaboration Brief

March, 2010

Page 2: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Copyright The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This White Paper is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS DOCUMENT. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred.

2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Server, Microsoft Office, Microsoft SharePoint Server, Microsoft SharePoint Server Foundation, Visual Studio are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners.

Page 3: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Applies To

Office Business Applications (OBAs)

Microsoft-SAP Interoperability Solutions

Microsoft SharePoint Server Foundation 2010

Visual Studio 2010

Silverlight 3.0

Keywords

Office Business Application (OBAs), Microsoft SharePoint Server Foundation 2010, Line-

of-Business (LOB), External Lists, SharePoint Client Object Model, SAP NetWeaver,

SAP ERP (ECC), Visual Studio 2010, Silverlight 3.0, SharePoint Designer 2010

Audience

Technical Consultants, Technical Architects, Solution Developers

Contact

This document is provided to you by Microsoft Corporation. Please check the SAP interoperability area at www.microsoft.com/sap and the .NET interoperability area in the SAP Developer Network at http://sdn.sap.com for any updates or further information.

Page 4: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Contents

Introduction ................................................................................................................... 2 SharePoint Business Data Connectivity Services (BDC) ............................................. 2 BDC Metadata and External Content Types ............................................................... 3

Connecting to Line-of-Business Systems ................................................................... 5 Data Types and Formats ............................................................................................ 5 Initialization of Interface Structures ............................................................................. 5 Service Composition ................................................................................................... 5 Identifiers .................................................................................................................... 5 Transaction Support and Session State ...................................................................... 6

Tooling ........................................................................................................................... 6 A Sample Solution ......................................................................................................... 7

Solution Overview ....................................................................................................... 7 Solution Implementation ............................................................................................. 8

Part 1: Exposing the LOB Interface ....................................................................................... 8 Part 2: Using Visual Studio 2010 to Create a Business Data Connectivity Model .............. 11 Part 3: Using SharePoint Designer 2010 to Create a SharePoint External List ................. 18 Part 4: Connecting a Silverlight application to an External List ........................................... 21

References ................................................................................................................... 31

Page 5: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Introduction

SharePoint Business Data Connectivity Services (BDC)

The Microsoft SharePoint Server Foundation 2010 provides an improved and expanded set of features that enable SharePoint and Office solutions to connect to external data, i.e. data that is stored in other systems, such as Line-of-Business (LOB) systems. The Business Data Connectivity (BDC) feature which was introduced with SharePoint Server 2007 has been expanded to enable read and write operations in the external system. Furthermore, the BDC now not only connects to database systems or Web services, it can also connect to a custom .NET assembly or a custom data source. In the case of a .NET assembly the developer can implement any logic that may be needed to communicate with the external system, for example if LOB-specific protocols or interfaces need to be utilized. The .NET assembly will encapsulate the specifics of the LOB interfaces underneath the BDC. A custom data source provides an extensibility option for developers who want to plug in their own connectors for different external system types. In addition to the BDC Services, SharePoint Server Foundation 2010 introduces a set of services that enable an Office client application, including Outlook, InfoPath or Access to integrate with business data, in both online and offline scenarios. For offline scenarios, business data is cached on the user‟s machine and synchronized with the external system when the connection is available.

Fig 1 – Business Data Connectivity Services

One of the key benefits of working with the BDC is that access to the external systems is provided through a set of standardized and system-independent interfaces. Once defined, a connection to an external system can be utilized in many different ways, within different applications. Within SharePoint Server, out-of-box list types, web parts, or services including Search can work directly with the BDC, without any additional development effort.

Page 6: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Similarly, the Office 2010 client applications, including Microsoft Outlook, InfoPath, Word, Access or SharePoint Workspace also take advantage of the BDC and offer out-of-box capabilities, including offline access, data synchronization and UI integration.

BDC Metadata and External Content Types

At the core of the BDC is a Metadata Model (BDC model). The BDC model defines the data structures for Entities (External Content Types) and Methods in an XML format. The main building blocks within a BDC model are External Content Types (ECTs) or Entities. At runtime, the BDC provides a SharePoint or Office client application access to an external system based on the entities and methods that are defined in the BDC model. For example, if you are developing a Purchasing solution, your external content types may include business entities such as Material or Vendor. Each of the business entities will define a set of standardized methods, including as Read, ReadList, Create, Update or Delete.

Fig 2 – BDC Metadata Model

Page 7: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Once you have the external content types defined, you can reuse them in many scenarios. In the Purchasing example from above, you can use an External List in SharePoint which will provide out-of-box UI functionality for the end user to display, create or update Material or Vendor data from the external system. An External List is similar to other lists in SharePoint. It enables the user to interact with list-based information, with the data being stored in the external system. For developers, an External List can be accessed using the same object model as other SharePoint list types. SharePoint Search can use an ECT to crawl external data and provide search functionality to the end user. Within the Microsoft Office application suite, the SharePoint Workspace client can be used to take an External List offline and continue to work with business data while disconnected. Similarly, Outlook 2010 can synchronize folders with external list data and integrate external content type data into the task pane or form regions. In Word 2010, Business Connectivity Services can expose external data in the body of a document in the form of content controls, thus creating a seamless document authoring experience. InfoPath forms can be auto-generated based on external content types, enabling the user to view or update business data using electronic forms that are rendered in the browser. Reusability across business scenarios and client applications is one of the key advantages of using External Content Types. The effort involved in developing an ECT largely depends on the complexity of your external system and how well the interfaces of the external system can be mapped to the standardized methods of the client application.

Page 8: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Connecting to Line-of-Business Systems

When working with LOB systems, the developer is often faced with additional complexities that are introduced because of the way data and business processes are exposed by the LOB system. The BDC on the other hand exposes entities and methods in a very uniform and LOB-independent structure so that it can work directly with standard SharePoint Server and Office components and interfaces. The solution developer has a number of options to address this gap, including the use of a .NET assembly as source type for the BDC which is outlined further below in this document. This approach allows the developer to implement additional logic required to address LOB-specific requirements in-between the BDC and the LOB interface. Following are some common examples of the type of issues the solution developer can be faced with when connecting to LOB systems:

Data Types and Formats

LOB systems often have their own definition of data types and formats to allow for multi-platform support. In an SAP ABAP system for example, a Date value is defined as an 8-character string in the format YYYYMMDD. A Time value is typically stored in a separate field as a 6-character string in the format HHMMSS. If the client application expects a .NET type of DateTime, the developer will have to address the type conversion and proper formatting outside of the LOB system.

Initialization of Interface Structures

LOB interfaces may require that data structures are initialized properly when called from a client system. For example, in an SAP ABAP system, the input and output structures of web service operations are often represented as array structures. For mandatory input structures, it is necessary to initialize the array instead of passing NULL values. Another example are input structures where specific fields have to be initialized with an update indicator (value = „X‟) to let the LOB interface know which fields are being updated during the method call.

Service Composition

A stereotyped method in the BDC (e.g. Read, ReadList, Create, Update, Delete) cannot always be directly mapped to a functionally equivalent interface in the LOB system. For example, to create a Purchase Order in an SAP system, you may have to first check the inventory level or the blocked status of a vendor, or to check which plants the selected material can be shipped from. Even a fairly straight forward core business process can involve multiple service calls to the LOB system to complete the process.

Identifiers

The BDC requires every entity to have a unique identifier. For example, to display a list of purchase order line items, each line item will require a unique ID. In the LOB system on the other hand, the purchase order line item ID might have to be determined by

Page 9: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

looking at the combination of the Purchase Order Header ID (e.g. “1234”) and the Purchase Order Line Number (e.g. “010”).

Transaction Support and Session State

When working with SAP Business APIs (BAPIs), an additional call to either complete or rollback a transaction. The transaction commit (or rollback) calls have to occur in the same web service session context as the method call to create, update or delete data. The developer is required to maintain the session state until the Transaction Commit (or Rollback) step is completed.

Tooling

Tooling for the development of BDC-based solution has been another significant area of improvement in the SharePoint Server 2010 release. For “simple” solutions, where you can connect the BDC directly to a web service or database, without any or less of the complexities introduced by LOB systems, SharePoint Designer 2010 can be used to author a BDC model with External Content Type definitions. Furthermore, you can use SharePoint Designer 2010 to create an external list on a SharePoint site or you can create an InfoPath form for the external content type. SharePoint designer provides a declarative design experience for an advanced user, without having to write code. For “advanced” solutions, where the developer needs to address some of the complexities outlined above or introduce additional logic, validation or custom UI, Visual Studio 2010 is the environment to develop code-based solutions. Visual Studio 2010 comes with support for SharePoint Server 2010 solution development, including a BDC Model project template with a .NET assembly as source system. Visual Studio also provides support for Silverlight application and Office Add-ins in the form of solution templates.

Page 10: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

A Sample Solution

Solution Overview

In the sample solution outlined in this whitepaper, a SharePoint site is used to display Material information from an SAP system to the end user. The source for Material information is an SAP ERP (ECC 6.0) system which exposes a BAPI as web service and provides the methods to read Material data. The web service is invoked by a .NET assembly which acts as the source system for a BDC model. The BDC model defines the Material entity and two methods – ReadItem and ReadList. Material information from SAP is surfaced in SharePoint in form of an external list. Finally, a Silverlight application is hosted in SharePoint and is able to access and display the material external list using the SharePoint Client Object model.

Fig 3 – Sample Solution Overview

SharePoint Server 2010

External List

BCS

.NET Assembly

SAP ERP (ECC 6.0)

Silverlight UI

BAPI as Web Service Interface

Material Info Client Object

Model

Page 11: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Solution Implementation

Part 1: Exposing the LOB Interface

As a first step in our sample solution, we will enable the required interface in the LOB system. In this sample solution, we will use an SAP BAPI interface to read Material information from the SAP system. A BAPI interface in SAP can be exposed as a Web service. For a detailed walk-through of how a BAPI in SAP can be exposed as a web service, using the underlying SAP NetWeaver infrastructure, please see the whitepaper at http://download.microsoft.com/download/a/2/8/a287c141-b72e-4e9e-aac5-826e3f0d6d76/StatefulNetWeaverCommunication.pdf This whitepaper also explains how a web service can be configured to be “stateful” which is required to perform an explicit Transaction Commit or Transaction Rollback operation in the SAP system from an external client. In an SAP system, the ABAP Developer Workbench (SAPGUI transaction code: SE80) can be used to launch into the SAP Web Service wizard. The wizard will guide you through the steps for exposing a web service. In this document only the screens relevant to the sample solution will be outlined. For the general procedure of exposing a BAPI or Function Module as a Web service, please see the whitepaper referenced above.

Fig 4 – SAP ABAP Developer Workbench

Page 12: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

For our sample solution, we are using a BAPI from the SAP Application area ‟Logistics – Master Data‟ (LO-MD) with a BAPI called „Material‟

Fig 5 – SAP Web Service Wizard - Material BAPI

When you choose the operations to be included in your Web service, you only need to choose the ones that you want to make available via the SharePoint BDC. In our sample application we will need the operations GetList and GetItem.

Fig 6 – SAP Web Service Wizard - Choose Operations

Page 13: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

After completing the creation of the web service in SAP, you can verify that the service is available using the Web Service Administration tool (transaction SOAMANGER in SAPGUI). In the Web Service Administration tool, you can find your service and browse to the WSDL for it. You will later need this WSDL to create the Web service reference in your Visual Studio project.

Fig 7 – SAP Web Service Administration

Page 14: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Part 2: Using Visual Studio 2010 to Create a Business Data Connectivity Model

Now that we have enabled a web service in our LOB system for material information, we can start developing the BDC model. Visual Studio 2010 offers new project templates to support the creation of SharePoint 2010 solutions, including a template for Business Data Connectivity Model projects.

1. Create a new Business Data Connectivity Model project:

a) Start Visual Studio 2010 b) Select New Project and from the list of Installed Templates, expand the

SharePoint node under the language that you want to use, and then click 2010 (for this whitepaper we are using Visual C#)

c) In the Templates pane, select Business Data Connectivity Model. Name the project (e.g. BDCSampleProject), and then click OK

d) The SharePoint Customization Wizard appears. This wizard enables you to select the site that you will use to debug the project and the trust level of the solution.

e) Click Finish to accept the default local SharePoint site and default trust level of the solution

Fig 8 – Business Data Connectivity Model Project Template

Page 15: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

f) Visual Studio will create the new Business Data Connectivity project. The project will contain a BDC Model item with the default name BdcModel1.

2. Rename the default items in the BDC Model: Visual Studio will create a default BDC Model project, with a default entity definition (Entity1). When you rename the default entity, make sure that you inspect all the properties of every item in the BDC model as well as any auto generated code to ensure that all default names have been renamed properly. a) In the Solution Explorer, rename:

BDCModel1 to SAPModel BDCModel1.bdcm to SAPModel.bdcm Entity1.cs to Material.cs Entity1Service.cs to MaterialService.cs

b) Double-click on the item SAPModel to display the BDC Explorer and model

design surface. The BDC Model will have one default entity (Entity1) with a default identifier (Identifier1) and the minimum required methods ReadList and ReadItem.

Fig 9 – Business Data Connectivity Model Design

Page 16: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

c) In the BDC Explorer, expand the entire tree under the Model node and rename: Model1 to SAPModel LobSystem1 to SAPSystem LobSystemInstance1 to SAPECC6 Entity1 to Material Identifier1 to MaterialID

3. Define the Material entity: Switch back to the Solution Explorer window and open the Material.cs file. Define the fields for the Material entity as a C# class:

namespace BdcModelSample.SAPModel

public partial class Material

{

public string MaterialID { get; set; }

public string MaterialDescription { get; set; }

}

4. Add the methods to the Material entity:

For our sample solution, we will implement the two minimum required methods for an entity in the BDC – ReadList and ReadItem. With these two methods implemented, we can display data in an external list in SharePoint.

a) In Solution Explorer, right-click References -> Add Service Reference -> Advanced -> Add Web Service

b) In the Add Web Service dialog, specify the URL of the SAP Material web service WSDL in the URL field

c) Specify a name for the web reference (e.g. SAPMaterialWebService) and select Add Reference

Page 17: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Fig 10 – Add Web Reference

d) Switch to the model design (open item SAPModel.bdcm), right-click the ReadItem method of the Material entity and choose View Code (F7)

Fig 11 – BDC Methods – Code View

Page 18: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

e) Add the code for the ReadItem operation of the Material entity:

namespace BdcModelSample.SAPModel { public class MaterialService { public Material ReadItem(string id) { Material material = new Material(); SAPMaterialWebService.service client = new SAPMaterialWebService.service(); client.Credentials = new NetworkCredential("user","password"); SAPMaterialWebService.MaterialGetDetail request = new SAPMaterialWebService.MaterialGetDetail { Material = id, Plant = "BP01" }; client.AllowAutoRedirect = true; SAPMaterialWebService.MaterialGetDetailResponse response = new SAPMaterialWebService.MaterialGetDetailResponse(); response = client.MaterialGetDetail(request); material.MaterialID = id; material.MaterialDescription = response.MaterialGeneralData.MatlDesc; return material; } } }

f) In the model design editor (open item SAPModel.bdcm), right-click the ReadList

method of the Material entity and choose View Code (F7)

Page 19: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

g) Add the code for the ReadList operation of the Material entity:

namespace BdcModelSample.SAPModel

{

public class MaterialService

{

public IEnumerable<Material> ReadList()

{

Material[] materialList = new Material[1000];

SAPMaterialWebService.service client = new

SAPMaterialWebService.service();

client.Credentials = new NetworkCredential("user",

"password");

//initialize BAPI request parameters

SAPMaterialWebService.MaterialGetList request =

new SAPMaterialWebService.MaterialGetList();

SAPMaterialWebService.Bapimatram[] matSelection =

new SAPMaterialWebService.Bapimatram[1];

matSelection[0] = new SAPMaterialWebService.Bapimatram

{

Sign = "I",

Option = "CP",

MatnrLow = "*",

MatnrHigh = ""

};

SAPMaterialWebService.Bapimatras[] descSelection =

new SAPMaterialWebService.Bapimatras[1];

descSelection[0] = new SAPMaterialWebService.Bapimatras

{

Sign = "I",

Option = "CP",

DescrLow = "*",

DescrHigh = ""

};

request.MatnrSelection = matSelection;

request.MaterialShortDescSel = descSelection;

SAPMaterialWebService.MaterialGetListResponse response =

new SAPMaterialWebService.MaterialGetListResponse();

response = client.MaterialGetList(request);

for (int i = 0; i < response.MatnrList.Length; i++)

{

materialList[i] = new Material();

materialList[i].MaterialID =

response.MatnrList[i].Material;

materialList[i].MaterialDescription =

response.MatnrList[i].MatlDesc;

}

return materialList;

}

}

}

Page 20: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

5. Test and Debug your LOB integration code:

It can be helpful to implement a test application (e.g. a simple C# Console Application) which invokes the ReadItem and ReadList methods to step through and debug your code. This will allow to monitor input and return values for your web service calls and detect common issues, like initialization problems, authentication problems etc..

6. Build and deploy your project: You can directly deploy your project to a SharePoint site. You can define the site URL in the properties of your BDC project.

Page 21: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Part 3: Using SharePoint Designer 2010 to Create a SharePoint External List

Now that our BDC model has been deployed to SharePoint, we can use SharePoint Designer 2010 to view the BDC model and create an external list on SharePoint site. 1. View the deployed BDC Model:

a) Open SharePoint Designer and connect to the SharePoint site containing the

deployed BDC model b) Select External Content Types from the Site Objects lists c) From the list of External Content Types, select

BdcModelSample.SAPModel.Material

Fig 12 – External Content Types in SharePoint Designer

Page 22: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

2. Create an External List: a) In the External Content Type page, select the Create Lists & Form command b) In the Create List and Form dialog, select the Create New External List option c) Specify a name for the list (e.g. SAPMaterial) and accept the default values for

Read Item Operation and System Instance

Fig 13 – Creating an External List with SharePoint Designer

Page 23: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

3. Verify the results in SharePoint:

a) Open the SharePoint site where you created the External List b) Navigate to the External List for SAP Material

Fig 14 – External List in SharePoint

Page 24: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Part 4: Connecting a Silverlight application to an External List

In this part, we will create a simple Silverlight application that displays the SAP Material list in a Silverlight grid control. Silverlight applications run on the user‟s machine and can provide a richer user experience and less load on the server compared to server-based web applications.

1. Creating a new Silverlight Navigation Application project:

a) Start Visual Studio 2010 and choose File -> New -> Project b) From the Silverlight template category, choose Silverlight Navigation

Application and provide a name for the solution (e.g. „SAPMaterialList‟) and click the OK button:

Fig 15 – Silverlight Project Templates

Page 25: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

c) Visual Studio will ask if you want to host the Silverlight application in a Web site. d) For new projects, this is a recommended approach and can help reduce

problems further down the road when the Silverlight application is deployed to a web server.

e) Check the Host the Silverlight application in a new= Web site box and accept the default values and click the OK button:

Fig 16 – Silverlight Hosting Options

f) A new Visual Studio solution will get created, containing two projects:

The C# Silverlight project SAPMaterialList, with the following items: o App.xaml – this file is the entry point to our application and also the

container for application-wide resources o MainPage.xaml – a default page representing the starting user interface

for the application. The page is show in the design and XAML view of the Visual Studio editor

o Assets & Views folders – these two folders contain application assets such as files, images, styles etc. and additional UI views, like the Home, About or Error pages

The C# Web project SAPMaterialList.Web ith the following items:

o Client.Bin folder - contains the compiles Silverlight application (XAP extension). An XAP file is an archive (ZIP) file. To view the contents, you can rename the extension of the file to .ZIP. The XAP file is hosted on the web server and is downloaded to the browser when the user navigates to the page that hosts the Silverlight application.

o SAPMaterialListTestPage.aspx - default .aspx page hosting the Silverlight application in the Client.Bin folder

o SAPMaterialListTestPage.html – default HTML page hosting the Silverlight application in the Client.Bin folder

o Silverlight.js – Java script helper file used by the default HTML page to embed the Silverlight application in the HTML page

Page 26: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

o Web.config – the configuration file for the web application

Fig 17 – Silverlight Navigation Application

g) The default Silverlight Navigation project can be compiled and started in debug mode without any modifications. Visual Studio will create a web application on the local machine which will host the Silverlight application.

Page 27: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

h) Adding controls to the Home page Using the Silverlight controls from the Toolbox in Visual Studio, you can modify the UI of your application. For our sample solution, we will implement only a few changes to illustrate the process: o Remove the default TextBlock “Home” from the page o Add an Image control to the Home page (place the logo file in the Assets

folder of our project) o Add a Label control for the Material List to the Home page o Add a DataGrid control to show the Materials to the Home page

Fig 18 – Silverlight UI Design

Page 28: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Silverlight uses XAML (Extensible Application Markup Language) to separate the UI definition from the application logic: <Grid x:Name="LayoutRoot"> <Image Height="70" Name="HomePageImage" Stretch="Fill" Width="288" HorizontalAlignment="Left" Margin="25,12,0,0" VerticalAlignment="Top" Source="/SAPMaterialList;component/Assets/Litware_75.png" /> <dataInput:Label Height="24" HorizontalAlignment="Left" Margin="25,104,0,0" Name="LabelMaterialList" VerticalAlignment="Top" Width="288" Content="SAP Material List" FontSize="14" /> <data:DataGrid x:Name="xMaterialList" Height="262" HorizontalAlignment="Left" Margin="25,134,0,0" VerticalAlignment="Top" Width="288" /> </Grid>

2. Accessing SharePoint List Data from Silverlight:

A SharePoint list can be accessed from a Silverlight application in different ways: o Using the SharePoint Silverlight Client OM o Using the Lists web service (lists.asmx) o Creating a custom web service, which uses the SharePoint Server OM or BCS

OM to access list data

For this sample solution, we will illustrate how the SharePoint Silverlight Client OM can be used to access a SharePoint external list:

a) Add the references for the libraries Microsoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll to the Silverlight project. (Note: you may run into the following issue when adding the references: http://www.andrewconnell.com/blog/archive/2009/11/19/fyi-ndash-interesting-little-bug-in-vs-2010-beta-2.aspx)

Page 29: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

Fig 19 – Silverlight Client Library References

b) We will use the Home.xaml page of our sample solution to show the Material list. Open the code-behind file Home.xaml.cs and add the definitions for web, list collection and list item collection: using Microsoft.SharePoint.Client;

namespace SAPMaterialList public partial class Home : Page { Web web; ListCollection collList; ListItemCollection collListItem;

Page 30: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

c) When the user navigates to the Home page of the Silverlight app, we will invoke the LoadMaterialList() method. Within the method, we initialize the client context to the SharePoint site which hosts the Material list that the Silverlight app will access. The method will make an asynchronous call to execute a CAML query to return all records from our SharePoint list:

protected override void OnNavigatedTo(NavigationEventArgs e) { LoadMaterialList(); } private void LoadMaterialList() { ClientContext clientContext = new ClientContext("SiteURL"); web = clientContext.Web; collList = web.Lists; var matList = collList.GetByTitle("SAPMaterial"); CamlQuery cq = new CamlQuery(); collListItem = matList.GetItems(cq); clientContext.Load(collListItem); clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed); }

The callback methods for the asynchronous query:

private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args) { UpdateUIMethod updateUI = DisplayMaterialList; Dispatcher.BeginInvoke(updateUI); } private void onQueryFailed(Object sender, ClientRequestFailedEventArgs args) { // query error }

Page 31: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

d) We need to define the MaterialData structure for display in our data grid. We also need to implement the DisplayMaterialList() method which binds the external list data to the data grid control XMaterialList.

e) Finally, we need to add the definition for delegate method UpdateUIMethod which is used to enable an asynchronous method call:

public class MaterialData { public string MaterialID { get; set; } public string MaterialDescription { get; set; } } private void DisplayMaterialList() { List<MaterialData> source = new List<MaterialData>(); { foreach (ListItem material in collListItem) { source.Add(new MaterialData() { MaterialID = (string)material["MaterialID"], MaterialDescription = (string)material["MaterialDescription"] }); } xMaterialList.ItemsSource = source; } } private delegate void UpdateUIMethod();

Page 32: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

f) Test the application in debug mode:

Fig 20 – Silverlight Application in Debug Mode

Page 33: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

3. Hosting your Silverlight Application in SharePoint:

You can host your Silverlight application directly in SharePoint using the Silverlight Web Part which is provided in SharePoint Server 2010. When you build your Silverlight project in Visual Studio, a Silverlight application file (.xap) is generated in the output path of your project. You can import the .xap file to a library on your SharePoint site (e.g. a document library). When you add a Silverlight web part to your SharePoint page, you configure the web part with the URL of the Silverlight application file (.xap).

Fig 21 – Silverlight Web Part in SharePoint

Page 34: Connecting_a_Silverlight_Application_to_Line-of-Business_Information

Connecting a Silverlight Application to Line-of-Business Information

References

SAP Help Portal http://help.sap.com Microsoft SAP Customer Information Center http://www.microsoft.com/isv/sap/ SAP Developer Network http://sdn.sap.com Microsoft Developer Network http://msdn.microsoft.com