First steps on the SharePoint 2010 BCS path

Because of my work as an integration consultant I’m interested in the new BCS capabilities in SharePoint 2010. It is always good to find out personally what you can and what you cannot do with new technology.

At the SharePoint 2010 connections in the RAI conference center in Amsterdam I saw a nice demo presented by Steve Fox. Like all Microsoft demos things look much easier than in they are in reality.

To find out myself I started a small project. I took this blog by Steve Fox as a guideline because it would be great to get that working in the first place.

I decided to start with the SharePoint Designer to see what you can achieve with regards to the BCS. It turned out that you can create connectivity with SQL Server databases via BCS with the SharePoint Designer very easily. Just click a few times and you can create an external list talking to the database. Cool! I saw a few other options that I would like to investigate more at a later time but are out of scope for now.

Next the Visual Studio approach. I learned a best practice to always start with an empty SharePoint project and then add the necessary items. I added a ‘Business Data Connectivity Model’

By leaving everything to default, this is what the solution and entity looks like:

New BCS Solution New BCS Entity

Because I didn’t like the defaults I decided to change the name of the feature and BDC model. Then I added a WCF Service library to function as service layer between the SharePoint 2010 external list and the SQL Server database. At the end the solution and entity looked like this:

BCS Solution BCS Entity

Actually that is where the trouble began. One advice, don’t change the defaults if you’re trying to learn BCS. Just changing the ‘Identifier1’ into ‘CustomerId’ can cause serious trouble and your external list just won’t work. You have to dive into the SharePoint logs to figure out what exactly is going on. The good thing is that I know now where to find the logs (C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14LOGS).

The basic thing is that you have to define an entity which represents the object you’re retrieving. For me it was nothing more than the following, much like in Steve’s blog:

public partial class MyDidagoEntity
{
    public string CustomerId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Street { get; set; }
    public string Zipcode { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
}

Then you implement the ‘CRUD’ methods in the entity service.

  • ReadItem
  • ReadList
  • Create
  • Update
  • Delete

In the entity service I called my own WCF service and mapped the objects coming from the WCF service to the entity I defined as ‘MyDidagoEntity’. The ReadItem mehod looks like this:

public static MyDidagoEntity ReadItem(string id)
{
    // Call the service to get the data
    DidagoService.DidagoServiceClient client = new  DidagoService.DidagoServiceClient();
    DidagoService.Customer customer = client.GetCustomerById(int.Parse(id));

    MyDidagoEntity MyDidagoEntity = new MyDidagoEntity();
    MyDidagoEntity.CustomerId = id;
    MyDidagoEntity.FirstName = customer.FirstName;
    MyDidagoEntity.LastName = customer.LastName;
    MyDidagoEntity.City = customer.City;
    MyDidagoEntity.Country = customer.Coutry;
    MyDidagoEntity.Street = customer.Street;
    MyDidagoEntity.Zipcode = customer.Zipcode;
    return MyDidagoEntity;
}

One thing I learned so far is not to change the type of the Id of the item you want to read. I changed this from ‘string’ to ‘int’ but didn’t get away with it. I have to dive into this but to get this working, leave it as string.

There are tools in Visual Studio (like the BDC Explorer) that help you with building and changing the XML definition (which is still there), but one way or another I ended up search and replacing things in the XML definition anyway.

The final challenge was to get the WCF client configuration in the right web.config. Because I mostly skipped SharePoint 2007 I had to learn where to put it. After some trial and error I found out it should be in C:inetpubwwwrootwssVirtualDirectories80web.config.

To make a long story short: I got it to work!

It actually is a pretty cool technology that I expect to be used by a lot of companies. I’m sure I’ll run into this in the future so it is my job to be prepared.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>