WCF WebHttp Services .NET 4.0 web page unavailable when browsing to a method in service. Running on development web server in VS 2010
I've built a WCF Service in .NET 4.0 that basically just does standard CRUD to a couple of tables on a MS SQL Server 2005 database. I'm using an ADO .NET Entity Data class to map to the database tables. So far, this has been really simple. I've just pulled the tables onto the design surface and let the tool do the work for me.
Here's my issue. One of the methods of the service gives me an error (Internet Explorer cannot display the webpage) when trying to get any data from it. IE acts like it can't contact the server, but the server is my local machine, and it can, in fact, contact the server when I browse to different methods. Here's the method:
[WebGet(UriTemplate = "POS_AllowedValues")]
public List<POS_AllowedValues> GetAllowedValues()
{
using (DENTSPLYEntities dentsply = new DENTSPLYEntities())
{
var allowed = dentsply.POS_AllowedValues.ToList();
return allowed;
}
}
Unless I'm completely off my rocker, that should be returning a list of POS_AllowedVa开发者_开发知识库lues objects when hitting the URL of the service and adding "/POS_AllowedValues" to the end. When looking at the help page of the service, that is indeed what it would indicate.
Now, the thing that really kills me is that the other methods all work fine. For instance, here's the method GetPOSAccountXref
[WebGet(UriTemplate = "POS_AccountXref")]
public List<POS_AccountXref> GetPOSAccountXref()
{
using (DENTSPLYEntities dentsply = new DENTSPLYEntities())
{
var posXref = dentsply.POS_AccountXref.ToList();
return posXref;
}
}
That works fine! The only difference I can find so far at all between the two, is that the POS_AllowedValues object contains a navigation property to one of the other table entities, whereas the POS_AccountXref object does not.
I'm basically following the blog post found on blogs.msdn.com called Getting Started with WCF WebHttp Services in .NET 4.
Also, I am running this in the development web server in VS. This is entirely running on my dev box, using Windows 7 and VS 2010.
I really have no idea why this isn't working. Any help at all would be greatly appreciated.
Turn off the lazy loading on your object model. Lazy loading is used by default. When you return your list of POS_AllowedValues the serialization accesses navigation property and it tryes to load related entities. But at this time object context is already disposed and exception is thrown. If you want to send related objects as well you have to explicitly load them (eager loading) by using Include() function on the queried object set.
精彩评论