EPiServer Template Foundation WCF REST JSON service, part one
This blog series is about extending EPiServer Template Foundation (ETF) with a WCF service that can be accessed with REST and returns JSON. A’lot of acronyms means it’s really cool – right? Let’s get started!
With the advent of iPhone, Android and Windows Phone 7 the industry has been rushing into the direction of Apps. We see a tremendous rise in demand with our clients to push their business onto the App-scene. We as developers need to address this need and delight our crowd.
EPiServer has launched their mobile center for iPhone. This is a great App with a’lot of potential for web editors.So are we forgetting someone? Yes, the visitors of your site. I took a few laps around making it easy to extend an EPiServer website into being App-friendly.
With the birth of Page Type Builder (PTB) we eventually saw the offspring of ETF. PTB addresses the issue of having strongly typed pages, and ETF gives you a running start with your EPiServer website by making standard page types and functionality for accessing their information readily available after installation.
All this means that we can access strongly typed page types like Articles and Contacts in ETF. This is all well except that from an App-perspective you’d need to go the route of either web browser or consume RSS-feeds and parsing these.
My example is based on running Windows 7 64-bit with IIS 7.
You’ll need the following:
With everything downloaded and installed we need to make an adjustment in order to get WCF working properly. Else we’ll be seeing a nasty 404-error because we haven’t got a handler for our .svc-extension.
- Run a command window as administrator.
- Navigate to “C:windowsMicrosoft.NetFramework64v3.0Windows Communication Foundation” (without “64” if you’re running a 32-bit OS).
- Run the following command: ServiceModelReg –i
Now we should be good to go!
Setting up the project
Let’s add a new WCF Service Application project to our solution assuming you have created the EPiServer ETF website project using Ted Nyberg’s guide. I chose to call mine DBLOG.EPiCMS6Sandbox.Services while the EPiServer-website project with ETF is called DBLOG.EPiCMS6Sandbox.Website.
Add the following folders
Add the following assemblies to the [assemblies]-folder
Subsequently add references to these assemblies to your Services-project.
Now the project structure should look something like this:
While you could create the service directly inside the Website-project I chose not to because I’d like to be able to distribute the service to multiple websites by simply adding the .svc-file and the assembly.
The project on its own won’t be able to access anything EPiServer but when run in the same application domain as our Website-project we’ll be rockin’. Either approach is of course perfectly fine.
Okay! We’re all set to do get into the nitty gritty of coding! On to part two!