In this article we are going to see how we can access an external web service using Business connectivity Services in SharePoint 2010.
BCS is an evolution of the Business Data Catalog (BDC) capabilities of SharePoint 2007 that enhances the capability of SharePoint as a platform for developing composite applications. It provides out-of-box features, services and tools that streamline development to deeply integrate external data and services. BCS provides the capability to connect SharePoint 2010 and Office 2010 applications to any external system, whether it be a Line-of-Business (LOB) system, (such as Microsoft Dynamics, Oracle, or Siebel) a web 2.0 service, or a custom home-grown application.
Difference between BCS and BDC in SharePoint 2007
BDC entities, web parts and Business Data list columns were designed to provide a read-only window into external systems. BCS provides much deeper integration of external data directly into SharePoint and Office UI in a fully read-write fashion. External Content Types (ECTs) provide a superset of entity capabilities by allowing solution designers to describe both the structure of the external system and how that data should behave within SharePoint and Office. We believe that end users should not have to understand where data comes from; they should be able to view and interact with it in a simple and consistent way across client and server applications.
Key BCS features
Here is a peek at some of our headline capabilities:
Read-write. You can create, read, update and delete external data from SharePoint and Office applications.
More connectivity options. In addition to database and web services, connect to WCF services or plug your own code into a .Net assembly connector to handle transformation or aggregation of data. Full support for Claims-enabled services as well as Secure Store Service (formerly SSO) to map user credentials.
Design and customization tools. Huge investments in SharePoint Designer 2010 and Visual Studio 2010 to allow creation and customization of code-less and code-based solutions. Composite solutions can be collaboratively built by a team with each member using the tool(s) of their choice. Build applications faster and easier.
Rich Client integration. Expose data as a native SharePoint list and then connect it to SharePoint Workspace or Outlook. Customize InfoPath forms to add business logic surfaced consistently in SharePoint and SharePoint Workspace. Customize Outlook to provide views, forms, ribbon buttons or show contextual data in a taskpane - all without writing code!
Work online or offline. External data is cached in a SQL CE database installed with Office 2010. When connectivity is lost, the cache automatically goes into offline mode. When connectivity is restored, BCS can synchronize data changes directly to the external system.
Application Lifecycle. Deploy composite SharePoint solutions to Office 2010 machines, and enable users to check for updates to those solutions.
Now we can g o with the steps to consume a web service using BCS
- Open SharePoint Designer 2010 ("SPD")
- Click on External Content Types in Navigation as shown below
- From the ribbon click on external content types
- You will get the new external content type tab
- Change the name and display name as necessary by clicking on it.
- Select the most suitable office item type
Select an appropriate option for the Office Item Type. If you are planning to surface data within Office applications such as Outlook you need to specify the Office Item Type. If you have no plan to surface data inside Office applications you can keep the default value which is Generic List for the Office Item Type. You can use Appointment as the Office Item Type if the underlying data coming from the LOB system need be shown in the Calendar pane in Outlook. If you are brining data which can be shown in the Contacts pane in the Outlook such as Employees, Customers, Students, Dealers, etc... then you can use Contact as the Office Item Type.
- We will choose Generic list for our example.
- Click on Operations Design View on ribbon or External System.
- In the screen which you get click on add connection.
- Select WCF Service from the dropdown. You will get the below window.
- In service MetaDataURL give url of WSDL.
- Here I have created and hosted a simple web service: http://Servername/StudentDetails/Service1.asmx?WSDL
- In the service end point url give the url of web service: http://ServerName/StudentDetails/Service1.asmx
- Give a name. Let's give Training Connection.
- Click on OK.
- You can see the connection.
- You cannot save this content type without giving operations.
- ReadList Operation
- Right Click on a web method. In my web service I have created a sample web method StudentListAll()
[WebMethod]
public
List<Student> StudentListAll()
{
List<Student>
objListStudent = new
List<Student>();
Student objStudent =
new Student();
objStudent.nStudentId = 1;
objStudent.sStudentName = "Jibin";
objListStudent.Add(objStudent);
objStudent = new
Student();
objStudent.nStudentId = 2;
objStudent.sStudentName = " Remya";
objListStudent.Add(objStudent);
objStudent = new
Student();
objStudent.nStudentId = 3;
objStudent.sStudentName = "Simi";
objListStudent.Add(objStudent);
objStudent = new
Student();
objStudent.nStudentId = 4;
objStudent.sStudentName = "Nishila";
objListStudent.Add(objStudent);
//Student objS
= objListStudent.Find(item => item.nStudentId == nStudentId);
return
objListStudent;
}
- On the screen above right click on StudentListAll() and select New ReadList Operation. You will get the window as given below.
- Click on Next
- Again click on Next. You will get the below window.
- You can see an error in the Error and Warnings window. To get rid of the first error select nStudentId and set as the identifier by checking the checkbox.
- To get rid of the warning selects the student name and checks the Show in Picker checkbox.
- Click on Finish.
- Click on Save.
- Create Read Item operation
- I have a method in web service which takes the input a student id and returns details.
[WebMethod]
public Student
StudentList(int nStudentId)
{
List<Student>
objListStudent = new
List<Student>();
Student objStudent =
new Student();
objStudent.nStudentId = 1;
objStudent.sStudentName = "Jibin";
objListStudent.Add(objStudent);
objStudent = new
Student();
objStudent.nStudentId = 2;
objStudent.sStudentName =
"Simi";
objListStudent.Add(objStudent);
objStudent = new
Student();
objStudent.nStudentId = 3;
objStudent.sStudentName = "Remya";
objListStudent.Add(objStudent);
Student objS =
objListStudent.Find(item => item.nStudentId == nStudentId);
return objS;
}
- Click on Next and select Map to identifier to get rid of the errors.
- Then click Next.
- Click on Finish.
- Click on Create Lists and Forms in Ribbon.
- Give a name to the list.
- Click on OK.
- Now the list will be created.
- We can go to lists and libraries and see the list 'Physics Students' in External Lists.
- Click on preview in browser. You can see the external data in a list.
Note:
If you are getting 'Access Denied by Business Data Connectivity' go to Central Administration – Application Management – Manage Service Applications
- Select Business Data Connectivity Service from the list.
- Give the permissions. Check the list with that login (Login which is added above).