WCF 5.6 Data Service Quick Start

I am trying to get a WCF data service server that has been running for several days. I finally retreated today and just tried to do what a quick start shows. Nothing else .. and in a completely new project. Of course it will work.

But this is not so .. it failed just like my other tests.

I just follow suit. Using Visual Studio 2013 for web express and hosting uses IIS Express. I installed WCF Tools version 5.6, so Visual Studio has a WFC Data Service 5.6 template.

Its essence is that

create an ASP.Net application Select the type of MVC without adding any folders for anything other than MVC, and no unit tests, individual account authentication.

Add the Entity ADO.Net data model for the NorthWind database called NorthwindEntities in web.config, importing all the tables.

Add a WCF 5.6 service data item, name it NorthWind.svc.

Change the NorthWind.svc.cs support code to the following.

using System; using System.Collections.Generic; using System.Data.Services; using System.Data.Services.Common; using System.Linq; using System.ServiceModel.Web; using System.Web; namespace StackOverflowApp { public class NorthWindService : DataService<NorthwindEntities> { // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { config.UseVerboseErrors = true; config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead | EntitySetRights.WriteMerge | EntitySetRights.WriteReplace ); config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead| EntitySetRights.AllWrite); config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; } } } 

Now it is ready to be created and launched .. it should work .. yes?

I run it and go to the service. I am greeted by the following complaint.

 <div id="content"> <p class="heading1">Request Error</p> <p>The server encountered an error processing the request. See server logs for more details.</p> </div> 

How do I debug this? This is not a typical answer when going to a page that generates an error in the application or on a page that does not exist. I have a feeling that the data.service system is generating this response .. that it actually started processing the request .. but failed for some stupid reason.

I followed the instructions that I thought, but apparently I missed something. I went through the process several times to try and find what I might have missed to no avail.


Update:

Aha .. on another similar issue, they recommended adding verbose messages using config.UserVerboseErrors = true . It didn't matter to me ... but the alternative method of using attributes was sure! Decorating the class [ServiceBehavior(IncludeExceptionDetailInFaults = true)] now gives this more descriptive error.

The server encountered an error processing the request. The exception is the message 'Type expression' System.Data.Entity.Core.Objects.ObjectContext 'cannot be used to return type' System.Data.Objects.ObjectContext ''. See Server logs for more details. Trace exception stack: blahblah

+7
c # wcf wcf-data-services
source share
3 answers

It looks like you are using Entity Framework 6, which has not been released for so long. You need to follow some additional steps to make WCF Data Services 5.6 and EF 6 behave well.

You need to add the optional Nuget Provider Entity Framework package to the WCF service provider, and then instead of inheriting your service from the DataService<T> you inherit from EntityFrameworkDataService<T> .

Complete steps are provided on the data services blog here: http://blogs.msdn.com/b/astoriateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework -6.aspx

+10
source share

Yes thank you. Your answer is right Chris. I was able to find the problem, finally, after I turned on the decorated version of verbose messaging, and received additional information about the connection with the objects that are the problem.

So, I found the problem and fixed it, or at least I can get it to work using the quick start guide. Working with my own database is a bit squirley still .. returns an empty set when I know that I have items in the database .. but at least I now have Workshop-A to compare to find the problem. (Yeah! I found a problem there, I forgot to add the entitie connection to web.config for my database other than Northwind - so now everything works!)

Anyway, the first decent hint followed the error message (which did not appear until I turned on detailed messaging with the class attribute), found this note about a problem that is actually related to the WCF interface with EntityFramework 6. (if I would not upgrade to version 6 I probably would not have a problem)

https://entityframework.codeplex.com/workitem/896

Then I looked for issues with WCF 5.6 and EntityFramework6. and whalla .. there is an alpha version of WCF that solves the problem.

Please note that if you follow the instructions here verbatim, there is a problem (or was for me). Get alpha2 instead of alpha1 as it fixes a binding error. i.e.

 Install-Package Microsoft.OData.EntityFrameworkProvider -Version 1.0.0-alpha2 -Pre 

http://blogs.msdn.com/b/astoriateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework-6.aspx

+3
source share

To install alpha2 today 6/7/2014 "Install-Package Microsoft.OData.EntityFrameworkProvider -Pre". Also the version of Microsoft.Data.Services should be 5.6.0.0.

+1
source share

All Articles