Benutzer:MovGP0/70-489/BCS

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Implement Business Connectivity Services (BCS)

[Bearbeiten | Quelltext bearbeiten]

Create External Content Types

[Bearbeiten | Quelltext bearbeiten]

External content types[1] are used to connect to:

  • SQL data source
  • WCF services (SOAP Web Service)
  • OData Services
  • custom sources using a .NET Connector

Create Content Type using SharePoint Designer

[Bearbeiten | Quelltext bearbeiten]
  • External Content Types
  • External Content Type (creates new external content type)
  • name the connection
  • Add connection
  • uses the SQL Connection Wizard
  • Create User Impersonation using the Secure Store Service[2]
  • Create CRUD functionality

OData[3][4] supports connections to

  • SQL Server
  • SharePoint
  • Windows/SQL Azure
  • Online Services

Use OData in SharePoint App

[Bearbeiten | Quelltext bearbeiten]
  • open Visual Studio
  • create App for SharePoint 2013 project
  • right click on the project → AddContent Types for an External Data Source...
  • enter the URL to the OData service
  • select the entities
  • Visual Studio creates a Content Type that maps to the OData Service
  • edit the content type
  • create a filter to limit the max number of results

Optimize Queries for Performance and Throttling

[Bearbeiten | Quelltext bearbeiten]
  • SharePoint limits to 5000 records by default; throws ExceededLimitException
  • Limit on external content type can be set
  • Limit can be changed using Set-SPBusinessDataCatalogThrottleConfig[5]
$BCSProxy = Get-SPServiceApplicationProxy | wehre { $_.GetType().FullName -eq ('Microsoft.SharePoint.BusineesData.SharedService.BDCServiceApplicationProxy') }
Get-SPBusinessDataCatalogThrottleConfig -Scope Database -ThrottleType Items -ServiceApplicationProxy $BCSProxy | 
   Set-SPBusinessCatalogThrottleConfig -Maximum 20000 -Default 25000

Use Naming Convention

[Bearbeiten | Quelltext bearbeiten]

Users should adhere to a naming convention.

Example User Account Names
User Meaning
SP_Admin SharePoint Administrator Account
SP_Farm SharePoint Farm Instance Account
SP_Crawl SharePoint Crawler Instance Account
SP_UserSync SharePoint User Profile Synchronization Account
BCS_SQL_AdventureWorks Connection to AdventureWorks database using SQL Connection
BCS_OData_Northwind Connection to Northwind OData Service
  • Requires custom method created in Visual Studio
  • Filter can be added to External Content Type (.ecs) file in Visual Studio

Implement Methods

[Bearbeiten | Quelltext bearbeiten]
  • BCS Models define CRUD operations on external data source
  • BCS Indexing Connector is used to support crawling and indexing of external data sources[6]
    • Model File - Provide connection information to the external system and the structure of the data
    • Connector - Contains the code that connects to the external system and parses data[7]

Create Associations

[Bearbeiten | Quelltext bearbeiten]
  • Relationship between external data entities
in SharePoint Designer
  • External Content Types
  • select data source
  • right-click table
  • New Association
  • ...
in Visual Studio
  • see code example[8]

Implement Autorization and Authentication

[Bearbeiten | Quelltext bearbeiten]

BCS Supports the following authentication modes:

  • Pass-through
  • Revert to Self
  • Windows Credentials
  • Credentials
  • RDB Credentials
  • Digest Credentials
  • Custom Authentication

Pass-through, BCS Identity and User Identity

[Bearbeiten | Quelltext bearbeiten]
Credential Username and Password. Might include additional data based on system. Authentication can occur via:
  • Windows Authentication
  • Forms Based Authentication
  • Digest
  • Basic
Claims SAML Token (see also: SAML 2.0) for claims-aware services with Single Sign-on[9]
Authentication Modes
Authentication Mode Description
Pass-Through
(User's Identity)
passes the credentials of the current user
Revert to self passes the credentials of the application pool
Windows Credentials
(Impersonate Windows Identity)
uses the Secure Store Service to map the SharePoint User's Credentials to Windows Credentials
Credentials
(Impersonate Custom Identity)
uses the Secure Store Service to map the SharePoint User's Credentials to Web Service Credentials (WCF)
RDB Credentials uses the Secure Store Service to map the SharePoint User's Credentials to Database Credentials
Digest Credentials
(Impersonate Custom Identity)
uses the Secure Store Service to map the SharePoint User's Credentials to Digest Credentials (Basic Authentication, Digest Access Authentication)
siehe auch: HTTP-Authentifizierung
User Permission Levels
Permission Level Description
Edit user can propagate permissions to child objects
Execute user can execute operations on the external content types
Selectable in Clients user can create lists based on the external content type
Set Permissions user can set permissions on the external content type

Use a Custom Model

[Bearbeiten | Quelltext bearbeiten]
  • Implement ODataExtensionProvider:
using Microsoft.BusinessData.SystemSpecific.OData;
using System.Net;

public class MyBCSAuthenticationProvier : ODataExtensionProvider
{
   public override void AfterReceiveResponse(HttpWebResponse response)
   {
      ...
   }

   public override void BeforeSendRequest(HttpWebRequest request)
   {
      ...
   }
}
  • Deploy to GAC
  • Register Provider using New-SPODataConnectionSetting in PowerShell.[10]
  • Add LobSystemInstance element to the BCS Model (.ect file)[11]
<LobSystemInstances>
   <LobSystemInstance Name="Northwind BCS">
      <Properties>
         <Property Name="ODataServiceUrl" Type="System.String">http://services.odata.org/Northwind/Northwind.svc</Property>
         <Property Name="ODataServiceAuthenticationMode" Type="System.String">PassThrough</Property>
         <Property Name="ODataFormat" Type="System.String">application/atom+xml</Property>
         <Property Name="HttpHeaderSetAcceptLanguage" Type="System.Boolean">true</Property>
      </Properties>
   </LobSystemInstance>
</LobSystemInstances>

Create Custom Connectors[12]

[Bearbeiten | Quelltext bearbeiten]
  • Create BCS Model file in Visual Studio
  • open the .bdcm file to view it in the designer
  • add additional methods in the BDC explorer plane
  • implement the methods
  • (optional) implement Security Trimming[13] by implementing the BinarySecurityDescriptorAccessor method
  • (optional) implement Caching[14]
  • (optional) implement External Event Receiver[15]. SharePoint requires the following components:
    • Polling Service
    • Subscription Store
    • REST Notification Endpoints
Stereotyped Methods[16]
Method Description
Creator create a new entity
Deleter deletes an existing entitiy
Updater updates an existing entity
Finder (ReadList) returns a list of entities
Specific Finder (ReadItem) returns a single instance of an entity
EventSubscriber subscribe to an custom event source
EventUnsubscriber unsubscribe from an custom event source

Access BCS Data

[Bearbeiten | Quelltext bearbeiten]

Use BCS Web Parts

[Bearbeiten | Quelltext bearbeiten]
BCS Web Parts
  • Business Data List
    list of BCS items
  • Business Data Item
    detail view of an item that is selected in the list
    ConnectionsGet Item From → select list
  • Business Data Actions
  • Business Data Connectivity Filter
    filters the data in an connected list
  • Business Data Item Builder
    URL with query string to retrieve a business data item; not visible to the end user
  • Business Data Related List
    list of related items from an association

Use BCS Data in Workflows

[Bearbeiten | Quelltext bearbeiten]
  • works like a normal list
  • Workflow cannot be attached to BCS list, because the list is not in SharePoint and cannot notify the WF of changes
Namespaces
using Microsoft.SharePoint.Client;
using Microsoft.BusinessData.Runtime;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.MetadataModel.Collections;
Create
using(var context = new ClientContext("http://<server>/<site>"))
{
   var externalList = context.Web.Lists.GetByTitle("<list name>");
   var newListItem = externalList.AddItem(new ListItemCreationInformation());
   newItem["Key"] = "Key";
   newItem["FirstName"] = "First";
   newItem["LastName"] = "Last";
   newItem.Update();
   context.ExecuteQuery();
}
Read
var siteUrl = "http://<server>/<site>/";
using(var context = new ClientContext(siteUrl))
{
   // get reference to LOB object
   var web = context.Web;
   context.Load(web);
   var entity = context.Web.GetEntity(siteUrl, "ListName");
   context.Load(entity);

   lobSystem = entity.GetLobSystem();
   context.Load(lobSystem);

   var lobSystemInstanceCollection = lobSystem.GetLobSystemInstances();
   context.Load(lobSystemInstanceCollection);
   context.ExecuteQuery();

   // get BCS entity
   var entityId = new EntityIdentity(context, new object[] { 11000 });
   context.Load(entityId);

   var entityInstance = entity.FindSpecific(identity, "Read Item", lobSystemInstanceCollection[0]);
   context.Load(instance);
   context.ExecuteQuery();
   
   // read values from entity
   Console.WriteLine("Customer Key: {0}", entityInstance["Customer Key"]);
   Console.WriteLine("Name: {0} {1}", entityInstance["FirstName"], entityInstance["LastName"]);
   Console.WriteLine("Birthday: {0}", entityInstance["BirthDate"]);
   Console.WriteLine("Email Address: {0}", entityInstance["EmailAddress"]);
}
Find information for the BCS Client Object Model[18]
  • Model XML in Visual Studio
    names of methods and fields
  • SharePoint Designer → Operations View
  • Central Administration → Business Data Connectivity Service
    shows namespace and entity names

Use the BCS SSOM

[Bearbeiten | Quelltext bearbeiten]
Namespaces
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.BusinessData.Runtime;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.SharePoint.BusinessData.SharedService;
Query using SSOM
var list = SPContext.Current.Web.Lists.TryGetList("List Name");
if(list == null) return;

var query = new SPQuery();
query.ViewFields = @"<FieldRef Name='CustomerKey' /><FieldRef Name='Email Address' />";
query.RowLimit = 10;
var listItems = list.GetItems(query);

foreach(var item in listItems)
{
   Console.WriteLine("{0}", item["EmailAddress"]);
}
Query using BDC Object Model[19]
// get reference to LOB list
var siteUrl = "http://<server>/<site>/";
var bdcService = SPFarm.Local.Services.GetValue<BdcService>();
IMetadataCatalog catalog = bdcService.GetDatabaseBackedMetadataCatelog(SPServiceContext.Current);
IEntity entity = catalog.GetEntity(siteUrl);

// get entity
ILobSystem lobSystem = entity.GetLobSystem();
ILobSystemInstance lobSystemInstance = lobSystem.GetLobSystemInstances()[0].Value;
var identity = new Identity(11000);
IEntityInstance entityInstance = entity.FindSpecific(identity, lobSystemInstance);

// read entity properties
Console.WriteLine("Customer Key: {0}", entityInstance["CustomerKey"]);
Console.WriteLine("Name: {0} {1}", entityInstance["FirstName"], entityInstance["LastName"]);
Console.WriteLine("Birthday: {0}", entityInstance["BirthDate"]);
Console.WriteLine("Email Address: {0}", entityInstance["EmailAddress"]);
Important Classes
  • Entity
  • LobSystem
  • LobSystemInstance
  • EntityIdentity, Identity
  • Needs a BCS List
  • Creating a BCS List ist not possible via REST
  • Supported Verbs are: GET, PUT, POST, DELETE
Access Data with REST Call
URL Description
_api/list/getbytitle('listname') get the metadata for the list
_api/lists/getbytitle('listname')/items get all items from the list
_api/lists/getbytitle('listname')?select=Title get the title of the list
_api/lists/getbytitle('listname')/items?$select=Title get the titles from the items in the list
_api/lists/getbytitle('listname')/items?$select=Title&$filter=ID eq 35 get the title of item with id 35
var url = "/sites/examprep/_api/lists/getbytitle('Adventure%20Works%20Customers')/items?" 
          + "$select=CustomerKey,FirstName,LastName,BirthData,EmailAddress&Filter=CustomerKey eq 11000";

$(function(){
   $.ajax({
      url: url, 
      method: "GET", 
      headers: { "Accept": "application/json; odata=verbose" }, 
      success: function(data) {
         var results = 
            "Customer Key: " + data.d.results[0].CustomerKey + "<br />" + 
            "Name: " + data.d.results[0].FirstName + " " + data.d.results[0].LastName + "<br />" + 
            "Birthday: " + data.d.results[0].BirthData + "<br />" + 
            "Email Address: " + data.d.results[0].EmailAddress + "br />";
         $("#BcsRestDiv").html(results);
      }
   });
});

See also:

Implement Client-side BCS

[Bearbeiten | Quelltext bearbeiten]

Use Microsoft Office Apps, Microsoft Visual Studio Tools for Office

[Bearbeiten | Quelltext bearbeiten]
  • Microsoft Office App can access SharePoit Data via REST API or JavaScript Object Model (JSOM)[20]
  • Microsoft Office can be extended via a add-in[21]

Use Caching, Use SQL Replication, Implement Authorization and Authentication

[Bearbeiten | Quelltext bearbeiten]
  • BCS uses a client cache based on SQL Server Compact Edition.
  • Will be installed with Microsoft Office.
  • BCSSync.exe is responsible for sync operations.

consider:

  1. External content types in SharePoint 2013. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  2. Configure the Secure Store Service in SharePoint 2013. In: Technet. Microsoft, 30. April 2014, abgerufen am 17. Juni 2014 (englisch).
  3. Open Data Protocol by Example. In: MSDN. Microsoft, März 2010, abgerufen am 17. Juni 2014 (englisch).
  4. OData Ecosystem. Microsoft, abgerufen am 17. Juni 2014 (englisch).
  5. Set-SPBusinessDataCatalogThrottleConfig. 16. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  6. Enhancing the BDC model file for Search in SharePoint 2013. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  7. SharePoint 2013: MyFileConnector custom BCS indexing connector sample. In: Office Dev Center. Microsoft, 20. März 2013, abgerufen am 17. Juni 2014 (englisch).
  8. SharePoint 2013: Create multiple external lists with associations. 6. Februar 2013, abgerufen am 17. Juni 2014 (englisch).
  9. Single Sign-on (SAML Protocol). In: Microsoft Azure Documentation. Microsoft, 1. April 2014, abgerufen am 17. Juni 2014 (englisch).
  10. New-SPODataConnectionSetting. 12. Juli 2012, abgerufen am 17. Juni 2014 (englisch).
  11. SharePoint 2013: Access external data using OData extension provider and OAuth. 14. Mai 2014, abgerufen am 17. Juni 2014 (englisch).
  12. Overview of Business Connectivity Services in SharePoint 2013. In: Technet. Microsoft, 11. Juni 2013, abgerufen am 17. Juni 2014 (englisch).
  13. How to: Configure item-level security in SharePoint 2013. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 18. Juni 2014 (englisch).
  14. How to: Improve Business Connectivity Services Solution Performance When Using the Cache. In: Office Dev Center. Microsoft, 30. Juni 2010, abgerufen am 18. Juni 2014 (englisch).
  15. How to: Create external event receivers. In: Office Dev Center. Microsoft, 5. März 2013, abgerufen am 18. Juni 2014 (englisch).
  16. Implementing Stereotyped Operations in Your Methods. 14. März 2010, abgerufen am 18. Juni 2014 (englisch).
  17. Code Snippets: Using the SharePoint Client Object Model with External Lists. 5. März 2010, abgerufen am 18. Juni 2014 (englisch).
  18. BCS client object model reference for SharePoint 2013. In: Office Dev Center. Microsoft, 16. Juli 2012, abgerufen am 18. Juni 2014 (englisch).
  19. Using the BDC Object Model. In: MSDN. Microsoft, abgerufen am 18. Juni 2014 (englisch).
  20. Overview of apps for Office. In: Office Dev Center. Microsoft, 2. Mai 2014, abgerufen am 17. Juni 2014 (englisch).
  21. Create Add-ins and Customizations for Office by using Visual Studio. In: MSDN. Microsoft, abgerufen am 17. Juni 2014 (englisch).
  22. How to: Improve Business Connectivity Services Solution Performance When Using the Cache. 30. Juni 2010, abgerufen am 17. Juni 2014 (englisch).
  23. Privacy and security for apps for Office. In: Office Dev Center. Microsoft, 28. März 2014, abgerufen am 17. Juni 2014 (englisch).