Partilhar via


How to: Create an External Content Type Based on a Web Service

Applies to: SharePoint Server 2010

The External Content Type Designer in Microsoft SharePoint Designer 2010 supports the creation of external content types that connect to Web services. You can simply discover your Web service, point to the Web methods that will perform the operations you want and return the required data, and then use it to create your external content type without writing any code or XML.

In this topic, you will learn how to create an external content type named Customer that is based on the Person.Contact, Sales.Customer and Sales.Individual tables in the AdventureWorks SQL Server 2008 sample database.

Prerequisites

  • A server running Microsoft SQL Server 2008.

  • A server running Microsoft SharePoint 2010.

  • Microsoft SharePoint Designer 2010 installed on the client computer.

  • The Code Sample: AdventureWorks2008 ASP.NET Web Service provided with this SDK deployed on a Web server.

Creating an External Content Type Based on a Web Service

SharePoint Designer 2010 requires a SharePoint site to store the files and artifacts it generates (such as external lists, etc.) when you use the External Content Type Designer to create external content types. Therefore, as a first step, you need to create a SharePoint site on the server running SharePoint Server to store the artifacts of the external content type and open it in SharePoint Designer on the client.

To define the general external content type settings

  1. In SharePoint Designer 2010, open the SharePoint site where you want to store the artifacts for the external content type.

  2. In the left navigation pane, click External Content Types.

  3. In the contextual Ribbon for entities, click External Content Type.

    This opens up a new External Content Type page.

  4. Click the New External Content Type link next to the Name and type WSCustomer.

  5. Click the New External Content Type link next to the Display Name and type WSCustomer.

  6. Select Contact from the Office Item Type dropdown. The figure below shows the general settings for the external content type.

    General settings for the external content type

To add a connection to the external system

  1. To specify the data source for the external content type, click Click here to discover external data sources and define operations.

  2. Click the Add Connection button under External Data Sources.

  3. In the External Data Source Type Selection dialog box, select WCF Service as shown below and click OK.

    Select external data source type

  4. In the WCF Connection dialog box that opens, enter the URL to the wsdl of the Web service in the Service Metadata URL field.

  5. Then enter the URL to the asmx page in the Service EndPoint URL.

  6. Enter the name as "AdventureWorksWS". The figure below shows the WCF Connection dialog.

    WCF Connection dialog

  7. Keeping the remaining settings as the defaults, click OK.

After validating the connection to the Web service address you specified in the previous steps, the Operation Design View pane lists the methods in the Web service definition in the Data Source Explorer window as shown below.

Web service methods in SharePoint Designer 2010

To define the supported operations and their parameters and filters

  1. Create a Create operation.

    1. Right-click the CreateCustomer method, and then click New Create Operation on the context menu. The Create wizard opens.

    2. In the Create wizard, click Next to keep the default name and display name values for the operation.

    3. Click the CustomerID parameter in the Data Source Elements group box.

    4. Select the Map to Identifier checkbox in the Properties group box as shown below.

      Map input parameter to identifier

    5. Click Next to continue to the Return Parameter Configuration page.

    6. Click the CustomerID parameter in the Data Source Elements group box.

    7. Select the Map to Identifier checkbox in the Properties group box.

    8. Click Finish button to complete the Create operation.

  2. Create a Read Item operation.

    1. Right-click the GetCustomerById method in the Data Source Explorer, and then select New Read Item Operation on the context menu. This context menu displays all the operation stereotypes supported by SharePoint Designer.

      The Read Item wizard opens.

    2. In the Read Item wizard, click Next to keep the default name and display name values for the operation.

    3. On the Input Parameters Configuration page, notice that there is an error in the Error Messages group box. This requires you to identify the identifier field for this external content type.

    4. To do that, click the CustomerId field in the Data Source Elements group box and select the Map to Identifier checkbox in the Properties group box.

      This sets the ID field as an identifier for this external content type, not just for this parameter. The error message disappears.

    5. Click Next to continue to the Return Parameter Configuration page.

    6. Click the CustomerID parameter in the Data Source Elements group box.

    7. Select the Map to Identifier checkbox in the Properties group box. Notice that field is marked Read-Only automatically.

    8. Next you need to map the fields like LastName, FirstName to Outlook properties. Select each field that can be mapped to a comparable Outlook property and map to it by selecting the appropriate field in the Office property field.

    9. Click Finish button to complete the Read Item operation.

  3. Create a Read List operation.

    1. Right click the GetCustomers method, and then click New Read List Operation on the context menu.

      The Read List wizard opens.

    2. In the Read List wizard, click Next to keep the default name and display name values for the operation.

    3. On the Input Parameters Configuration page, click Next to continue to the Return Parameter Configuration page.

    4. Click the CustomerID parameter in the Data Source Elements group box.

    5. In the Properties group, select the Map to Identifier checkbox.

    6. Select Last Name field and click the Show In Picker checkbox to enable the LastName field to be displayed in the External Data Item Picker. Repeat this step for FirstName.

    7. Click Finish to complete the Read List operation.

      Once you have created a Read Item and a Read List operation, you can create an external list by using this external content type.

      As you create operations for the external content type, you can see them in the External Content Type Operations part in the Operations Design View.

  4. Create an Update operation.

    1. Right-click the UpdateCustomer method, and then click New Update Operation on the context menu.

    2. In the Update wizard, click Next to keep the default name and display name values for the operation.

    3. Click the CustomerID parameter in the Data Source Elements group box.

    4. Select the Map to Identifier box in the Properties group box.

      Leave other parameters checked.

    5. Click Finish to complete the Update operation.

You have now successfully created the basic operations for the Customer external content type.

Basic operations for Customer

To save the external content type

  • Press CRTL+S to save the external content type to the BDC for the SharePoint site.

You can now use any of the presentation features of Microsoft Business Connectivity Services (BCS) to show the external data in Office 2010 and SharePoint 2010. The figure below shows an external list based on the WSCustomer external content type.

Customer external list