WCF Services and EPiServer

I just spent some time trying to get my WCF Service to work on my EPiServer CMS 5 R2 installation. It was a lot more complicated than I thought it would be.

I had built this Silverlight application using a test application, launching it in the VS webserver and everything was working fine. It was a small Silverlight application that used a WCF service to get some data from the server. The epplication worked perfectly...until I decided to deploy it to my "real" site using IIS 7... The "real" site was an EPiServer application which caused some problems.

I deployedmy Silverlight app as well as my service to the site I was going to use. Deploying the application meant copying the xap file as well as the svc and assemmbly to the server. I also copied my service configuration to the web.config file. After this I opened my browser and browsed to localhost. And behold...a broken Silverlight application. The application started, but soon came to a screeching halt as it tried to connect to the service. Since the application actually loaded, I came to the conclusion that the IIS configuration for the Silverlight things were ok and that it was the service that was the problem.

So I tried browsing to my service and got a 404.3 message. Hmm...wierd...So, Google to the rescue. I quickly found information telling me that the WCF services activation something wasn't automagically installed on Vista. So I went to the control panel and installed those parts.

After installing those parts, I went back to my browser and got another error. Now it said 404.4 file not found. Thats even more strange than the last message.The error page said that the handler associated with the request was the StaticFileHandler. I quickly realized that this couldn't be right. So I googled it and found the solution.

THe default web.config file in EPiServer has a <clear/> element at the top of the <handlers> section. This removes all http handlers defined in previously read configs and as such removes the handler for the .svc file extension. So to get it to work, you have to add a handler for "*.svc" that looks like the folowing:

<add name="SVCHandler" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" resourceType="Unspecified" preCondition="integratedMode" />

For more info I would recommend looking at the following blog posts:

Shows you how to handle 404.3 problems and install WCF services.

Old blog about .NET 3.0 RC1, but it gave me some needed information about how to set up the web.config file to get it to work after EPiServer changes it.

Comments (2) -

thanks, helped me a lot

Adam Jenkin 3/27/2012 3:35:52 PM

+1 I finally found this post after many hours of trying to get this to work!

In my instance, the service I had created uses the System.ServiceModel.Activation.WebScriptServiceHostFactory factory and to enable this work work, I have to also add:

<add name="svc-Integrated-4.0" path="*.svc" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv4.0" />

Comments are closed