Tuesday, July 20, 2010

BDC/BCS integration using WCF Service

I am sure you will find thousands of links on Business Connectivity Services (BCS) integrating with WCF Services. But, still I was not able to get it straight. I am documenting the pain points I faced hoping it will save that precious day.
As, the new term in SharePoint 2010 is BCS, I will try not to use its predecessor term BDC (Business Data Catalog). However both these terms will be interchangeably used in the blogs you find on net.
Following things you may want to verify when your WCF integration to your LOB is not working.
1) Ensure that you deploy WCF onto a web site in IIS. Don't try to host the WCF on the Visual Studio by debugging. It will throw an error that endpoint cannot be found.
Don't blame the SharePoint designer for not able to find the endpoint hosted on the Visual Studio.

2) When giving the URL at the SharePoint Designer give a fully qualified name of the machine and not just the machine names.
Local hosts are not welcome
You could try to add an entry in the hosts file of c:\windows\system32\drivers\etc\host
I added something like,
127.0.0.1 customers.server.com
My Service options were something like this,
http://mtalt005.server.com:8888/Collegue.svc?wsdl

3) Ensure that the WCF Service has anonymous access. Or else make sure that the service account running the WCF Service has appropriate permissions.
If appropriate credentials have to be used then you may want to consider adding an account in the Secure Storage Service of SharePoint and add that account in the Secure Storage Application ID when configuring the BCS.

4) Your Service should return a Composite (custom class) Object for Specific Finder i.e. ReadItem operation and an array of composite objects for Finder i.e. ReadList Operation. String or Array of Strings is not composite objects.

5) You will have to define the Filters when you are defining the input for the Read List Operations. This will be useful when you are expecting some input and return a list of objects.
Ex: Pass UserId as input to WCF Operation and expect a list of Collegues Objects.
// Sample
public class ColleguesSvc : ICollegue
{
public List GetAllCollegues(String userId)
{
// Read DB for the userId and get a list of Collegue objects and return them.
}
}
In the above case I had to define a filter at the Input Form of the ReadList Wizard.
FilterType = Comparison
Operator = Equals

6) Ensure that the Input parameter is String and not Int32. --- I am not sure about this. But I was facing some issue while doing this.

7) Ensure that you developed the WCF Service using Target Framework as 3.5
Though having 4.0 should not harm but just that you will have to make additional provision of reinstalling the IIS to ensure that it is compatible with 4.0. Windows Server 2008 R2 default comes with Framework 3.5. If you really want the WCF service to be 4.0 then make sure to have the application pool to be running under 4.0 and not 2.0

In the next blog I will mention about displaying the WCF content on a List.

No comments:

Post a Comment