Search This Blog

Wednesday, September 17, 2014

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
  1. Open SharePoint Designer 2010 ("SPD")
  2. Click on External Content Types in Navigation as shown below

    BCS1.jpg
     
  3. From the ribbon click on external content types

    BCS2.jpg
     
  4. You will get the new external content type tab

    BCS3.jpg
     
  5. Change the name and display name as necessary by clicking on it.
  6. 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.

    BCS4.jpg
     
  7. We will choose Generic list for our example.
  8. Click on Operations Design View on ribbon or External System.

    BCSdes.jpg
     
  9. In the screen which you get click on add connection.

    BCS6.jpg
     
  10. Select WCF Service from the dropdown. You will get the below window.

    BCS7.jpg
     
  11. In service MetaDataURL give url of WSDL.
  12. Here I have created and hosted a simple web service: http://Servername/StudentDetails/Service1.asmx?WSDL
  13. In the service end point url give the url of web service: http://ServerName/StudentDetails/Service1.asmx
     
  14. Give a name. Let's give Training Connection.

    BCS8.jpg
     
  15. Click on OK.
  16. You can see the connection.

    BCS9.jpg
     
  17. You cannot save this content type without giving operations.
  18. ReadList Operation
  19. 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;
    }

     
  20. On the screen above right click on StudentListAll() and select New ReadList Operation. You will get the window as given below.

    BCS10.jpg
     
  21. Click on Next
  22. Again click on Next. You will get the below window.

    BCS11.jpg
     
  23. 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.

    BCS12.jpg
     
  24. To get rid of the warning selects the student name and checks the Show in Picker checkbox.

    BCS13.jpg
     
  25. Click on Finish.
  26. Click on Save.
  27. Create Read Item operation
  28. 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;
     }


    BCS14.jpg

    BCS15.jpg
     
  29. Click on Next and select Map to identifier to get rid of the errors.

    BCS16.jpg
     
  30. Then click Next.

    BCS17.jpg
     
  31. Click on Finish.
  32. Click on Create Lists and Forms in Ribbon.

    BCS18.jpg
     
  33. Give a name to the list.

    BCS19.jpg
     
  34. Click on OK.
  35. Now the list will be created.
  36. We can go to lists and libraries and see the list 'Physics Students' in External Lists.

    BCS20.jpg
     
  37. Click on preview in browser. You can see the external data in a list.

    BCS21.jpg

    Note:

    If you are getting 'Access Denied by Business Data Connectivity' go to Central Administration – Application Management – Manage Service Applications
     
  38. Select Business Data Connectivity Service from the list.

    BCS22.jpg

    BCS23.jpg
     
  39. Give the permissions. Check the list with that login (Login which is added above).

No comments:

Post a Comment