If you are using Visual Studio Express for Web, you might notice that the WCF Data Service template is not available to use.
I’m going to explain a step-by-step guide to create a WCF Data Service.
Create an empty Web project with the name WcfDataServiceInExpressEditions:
Add the following nuget packages:
Add the following settings to the web.config right under
<configuration>
<system.webServer> <modules runAllManagedModulesForAllRequests="true"></modules> </system.webServer> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel>
Create an ADO.NET Entity Data Model and connect to any database you own and drag a couple of tables to the designer
Add a new WCF Service to your project name it: PubsService
Delete the file containing the interface IPubsService.cs
Change the declaration of your service as follows:
public class PubsService : DataService<Pubs> { // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: config.SetEntitySetAccessRule("jobs", EntitySetRights.AllRead); // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } }
Change the markup of the .svc file to include the correct factory:
Factory="System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services"
That’s it, run the application, and you will see something like this:
This is the list of all the tables configured in the InitializeService
method
To test the queries try something like this:
http://localhost:55575/PubsService.svc/jobs/?$filter=min_lvl gt 150
Download the code of this article
Happy coding
I can run your project, alternative ?
ReplyDeleteThe Visual Studio version used in this article is:
DeleteMicrosoft Visual Studio Express 2012 for Web
Version 11.0.50727.1 RTMREL
Microsoft .NET Framework
Version 4.5.50709
What's the exact error you are receiving?
This comment has been removed by the author.
ReplyDelete