Muhammad Ali Khan

MS CRM 3.0, MS CRM 4.0, Sharepoint 2007 & Sharepoint 2010

Business Connectivity Services (BCS) Using WCF & SharePoint Designer 2010

Posted by Ali Khan on January 11, 2010

In this post, I will consume a simple WCF service in SharePoint 2010 Designer and create an external content type (formerly known as Entities in BCD).

Step 1:Create the WCF Service & Deploy In IIS

My First step is to create the WCF service. There is nothing fancy about the code, I have one simple “Project” Contract with CRUD methods defined (that later I will consume in BCS), these methods are using LINQ to SQL to my test SQL Server Database (ProjectDB). Here is the WCF Contract.

image

And here is its implementation

image

You can download the full code (along with the application definition file from here “Download Code, you can import this application definition file from the Central Administration).

Step 2: Create External Content Type In SharePoint Designer 2010 From WCF Service

After deploying the WCF service in IIS, now let’s move to SharePoint 2010 Designer and create the BCS External Content type from this WCF Service. Open any site in SharePoint 2010 Designer ==> Click External Content Types.

image

Click “External Content Type” in the Ribbon to create a new External Content type. Fill the “Name” and other properties as shown below.

image

Click the line “Discover external data source and define operations” and in the new screen, click “Add Connection” and select “WCF Service”.

image

Fill in the properties “Service Metadata URL”, “Service Endpoint URL” and namespace and the click ok. It will download the metadata from the WCF contract and generate the BCS External Content Type for you.

 imageAfter click ok, the external content type from WCF will look like this. Now you have to define the operations for this external content type.

image

Now one by one, you will generate the method for CRUD (Create, Retrieve, Update, and Delete) and Retrieve List. Here is the step by step procedure for the create method. Right click “Create” and select “New Create Operation”, a wizard will open up.

image

image

image

Now Click “Finish”, it will generate the “Create Method” for this external content type. Similarly, generate the method for other operations. Now your “External Content Type” will look like below,

image

Save the “External Content Type”, by pressing “Save Icon” in the SharePoint 2010 Designer at the top.

image

Step 3: Configure External Content Type Profile Page in Central Administration

Now go to Central Administration ==> Application Management ==> Service Application ==> Business Data Connectivity and click “Manage” from the top Ribbon. You will see the screen below,

image

Click “Edit” from the Ribbon and select “Configure” to configure the path for the “Profile Page” and click ok. See the diagram below.

image

Generate the profile page for the External Content Type “WCFProject” by click on the dropdown ==> “Create/Upgrade Profile Page”.

image

So Now if you browse to any project with the above URL (e.g. http://win-1r2gn7r1jaq:8000/_bdc/AliProjects_WCFSP2010/WCFProject_1.aspx?ProjectID=9e02b936-2d41-4031-a2f0-6b8e8c6367e8), you will get a profile page for the project as shown below.

image

Step 4: Displaying WCF Service Data In SharePoint List

Now we will create an “External List” to consume this data from WCF Service  as shown below.

image

image

Select the “External Content Type (WCFProject)” and click “Create” to create the list. It will pull the listings for all the projects from the WCF “ReteriveMultiple” Method as shown below.

image

Now you can “Create”, “Update”, “View” and “Delete” any “Project” and it will call WCF Method internally to perform the operation. See the example of the delete below.

image

Here is the “Create” form.

image

In Brief, With SharePoint 2010, now we can easily create connect our existing WCF Service with the SharePoint and display, edit,create and delete the data inside the portal.

That’s it :).

Advertisements

11 Responses to “Business Connectivity Services (BCS) Using WCF & SharePoint Designer 2010”

  1. […] Follow this blog for setting up and connecting to your BCS via an External Content Type in SharePoint Designer […]

  2. Andrew Pelt said

    Great Post. Can you email me back, please. Thank you.

  3. Richard Reukema said

    I’m wondering how you might create a drop-down list for say “manager” in the above example. Can you combine a new lookup column for an external content type? I’m new to Sharepoint so I’ not use to these constructs.

    Regards,
    richard

  4. Guru said

    same requirements richard,

    I have data of user,, but while creating the new item. i need to flush those data to textboxes wich appears before pressing ‘save’,
    and also i need to select his business type so that designation autumaticaly fill into another text box,, remainin boxes he can enter. how can i achieve it.. i hv created list n all, just need to flush data, please help me.
    mail : guruprasadmarathe@gmail.com

  5. Ram said

    Good post. but how do i send data back

    • Ali Khan said

      Hi Ram,
      By “Send data back” insert/update in the Datasource i guess?
      It is mentioned in the same post above. you have to create the methods for “Create”, “Update” operation as described above.

  6. Terrence Kunstek said

    Everything here worked as advertised. First, I created a WCF service with CRUD operations which wrapped a SQL Server Compact 3.5 database table, then tossed it on the other side of the internet just for good measure. Next, the account I was using in SharePoint Designer 2010 was getting permission denied when attempting to add a connection. To fix that, Central Admin => Application Management => Manage service applications =>Business Data Connectivity Service (Manage in Ribbon) => Set Metadata Store Permissions (in ribbon) =>add account, grant all rights.

    After that, in Step 2 I mapped the (five) CRUD operations as shown. I skipped Step 3. Step 4 I created the external list from inside SharePoint Designer 2010. Then it pulled from my source and listed all items in the database. I added new items, deleted items, and updated items successfully, and it was extremely fast considering the WCF Service and SharePoint 2010 where both inside virtual machines 1500 miles apart.

    I am very impressed. I setup the connectivity in a fraction of the time it took for me to do so using BDC in SharePoint 2007, and I didn’t have to edit a single XML file. Plus this works with WCF, oh the joy of SOA and ESB.

  7. Bassvix said

    Same problem with me, Insert/Update don´t work (value null error).

    Get Item is ok (retrive).

    Other problem: Step 3 its different. Not exists Edit…Configure…Profile Page, aparently its not necessary.
    To create the external list I use Sharepoint Designer.

  8. Really useful -WCF in sharepoint ftw!

  9. Hi ,

    Using the steps above i created external content type and external list. But when i try to use a column from that external list to populate a drop down in visual webpart i am getting some error. however for sql external content type i am able to populate.

    please reply it is quite urgent.

  10. […] I have an exterior composed content sort that consumes a WCF service. So much it’s a thing simple, much more than HTTP, no security, just for tests. Here is ordinarily a sample to acquire an idea. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: