Mar 23, 2010

Host WCF Data Service in SharePoint 2010

Creating a WCF data service based on Entity Framework is fairly easy in Visual Studio 2010 (see here for step by step), but two Major steps are:
  • Add Entity Framework Model:
  • Add WCF data service
A couple notices:
  • In web.config, the following connection string is added:
  • if you right click on .svc file in Visual Studio and View Markup, you will see something like the followings. The point is, it is not strongly named!
<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service=" EntityDataService.AWDataService" %>


Now let's host this WCF data service in SharePoint _vti_bin folder, just like listdata.svc:
  • Sign this project:
  • Strong Name AWDataService.svc Markup:
<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service=" EntityDataService.AWDataService, EntityDataService,Version=1.0.0.0,Culture=neutral,PublicKeyToken=d71e6a94584bc776" % >
  • Add an empty SharePoint project and add a sharepont mapping folder- ISAPI with following items:
    • an existing item: AWDataService.svc
    • a new item: web.config with the above connection string included
  • Add service dll into sharepoint package to be deployed into GAC:
  • Optimize by not including sharepoint project assembly in the package since it will be an empty dll otherwise
After deploy the sharepoint project, you should be able to browse this WCF dataservice as: http://yoursharePointserver/_vti_bin/DataServiceHost/AWDataService.svc