Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WebApi not returning expected data
Message
De
18/06/2014 10:08:19
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
WebApi not returning expected data
Versions des environnements
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602038
Message ID:
01602038
Vues:
46
Hi,

I've spent a couple weeks looking at the training courses on PluralSight and have a bit better understanding of Entity Framework and Web API stuff now. I am following through a John Papa course (http://pluralsight.com/training/Courses/TableOfContents/spa) and trying to adapt it to use EF Database First rather than Code First (since I have my database defined already). I think I've got that to work.

When it comes to writing my controllers and actually pulling data, I am not getting any data returned when I do

http://localhost:51673/api/scancodes
or
http://localhost:51673/api/scancodes/1

ScanCodes is just a simple table in my database with a primary key and a code and it has one record in it with primary key 1.

The first call above returns an empty array (displays on the page like this: [])

And the second call stops on the throw line in my code in Visual Studio with this error:
System.Web.Http.HttpResponseException was unhandled by user code
  HResult=-2146233088
  Message=Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
  Source=IBCPackageTracking.Web
  StackTrace:
       at IBCPackageTracking.Web.Controllers.ScanCodesController.Get(Int32 id) in d:\Documents\Visual Studio 2013\Projects\IBCPackageTracking.Web\IBCPackageTracking.Web\Controllers\ScanCodesController.cs:line 31
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
       at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  InnerException: 
This is my code in the ScanCodesController class:
        // GET api/scancodes
        public IEnumerable<ScanCode> Get()
        {
            return Uow.ScanCodes.GetAll().OrderBy(s => s.scn_desc);
        }

        // GET api/scancodes/5
        public ScanCode Get(int id)
        {
            var scanCode = Uow.ScanCodes.GetById(id);
            if (scanCode != null) return scanCode;
            throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
I am at a loss as to where to look to work out why it is not finding my data. Any suggestions?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform