Following my previous thread about WCF Data Services 5.0, here is how to activate your service without svc file.
With .NET 4.0 we can activate our WCF services directly from the web.config without svc file, which is quite nice and handy since I like having a class library for my service implementation and a host project (Web App, Win App) to expose my services…
So far, nothing really new, these posts already cover this:
- MSDN: <serviceActivations>
- [What’s new in WCF4] .svc-less Activation – or: “Look ma: my [REST] URLs look good!”
- WCF 4.0 svc file less activation and the ServiceHostFactory
My here was how to activate my WCF Data Service… and for this use the factory attribute of the serviceActivations/add element with the DataServiceHostFactory available in the Microsoft.Data.Services.dll installed by WCF Data Services 5.0.
1. Add the Microsoft.Data.Services DLL to the list of assembly names that are used during compilation:
Use sn.exe -T Microsoft.Data.Services.dll to get the PublicKeyToken
<system.web> <compilation debug="true" targetFramework="4.0"> <assemblies> <add assembly="Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </assemblies> </compilation> </system.web>
2. Activate your WCF Data Service:
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"> <serviceActivations> <add service="MyNamespace.MyService" relativeAddress="./myservice.svc" factory="System.Data.Services.DataServiceHostFactory" /> </serviceActivations> </serviceHostingEnvironment>
3. Test you service:
Navigate to your service url: http://localhost/myapp/myservice.svc…