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
In SharePoint Designer 2010, open the SharePoint site where you want to store the artifacts for the external content type.
In the left navigation pane, click External Content Types.
In the contextual Ribbon for entities, click External Content Type.
This opens up a new External Content Type page.
Click the New External Content Type link next to the Name and type WSCustomer.
Click the New External Content Type link next to the Display Name and type WSCustomer.
Select Contact from the Office Item Type dropdown. The figure below shows the general settings for the external content type.
To add a connection to the external system
To specify the data source for the external content type, click Click here to discover external data sources and define operations.
Click the Add Connection button under External Data Sources.
In the External Data Source Type Selection dialog box, select WCF Service as shown below and click OK.
In the WCF Connection dialog box that opens, enter the URL to the wsdl of the Web service in the Service Metadata URL field.
Then enter the URL to the asmx page in the Service EndPoint URL.
Enter the name as "AdventureWorksWS". The figure below shows the WCF Connection dialog.
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.
To define the supported operations and their parameters and filters
Create a Create operation.
Right-click the CreateCustomer method, and then click New Create Operation on the context menu. The Create wizard opens.
In the Create wizard, click Next to keep the default name and display name values for the operation.
Click the CustomerID parameter in the Data Source Elements group box.
Select the Map to Identifier checkbox in the Properties group box as shown below.
Click Next to continue to the Return Parameter Configuration page.
Click the CustomerID parameter in the Data Source Elements group box.
Select the Map to Identifier checkbox in the Properties group box.
Click Finish button to complete the Create operation.
Create a Read Item operation.
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.
In the Read Item wizard, click Next to keep the default name and display name values for the operation.
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.
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.
Click Next to continue to the Return Parameter Configuration page.
Click the CustomerID parameter in the Data Source Elements group box.
Select the Map to Identifier checkbox in the Properties group box. Notice that field is marked Read-Only automatically.
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.
Click Finish button to complete the Read Item operation.
Create a Read List operation.
Right click the GetCustomers method, and then click New Read List Operation on the context menu.
The Read List wizard opens.
In the Read List wizard, click Next to keep the default name and display name values for the operation.
On the Input Parameters Configuration page, click Next to continue to the Return Parameter Configuration page.
Click the CustomerID parameter in the Data Source Elements group box.
In the Properties group, select the Map to Identifier checkbox.
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.
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.
Create an Update operation.
Right-click the UpdateCustomer method, and then click New Update Operation on the context menu.
In the Update wizard, click Next to keep the default name and display name values for the operation.
Click the CustomerID parameter in the Data Source Elements group box.
Select the Map to Identifier box in the Properties group box.
Leave other parameters checked.
Click Finish to complete the Update operation.
You have now successfully created the basic operations for the Customer external content type.
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.