开发者

Why aren't my WCF Data Services collections being listed?

I'm trying to make a simple WCF Data Service. I am able to successfully access the scv file but my Cars collection doesn't get listed. The content of my scv is:

[DataServiceKey("VIN")]
public class Car
{
    public String VIN { get; set; }
    public String Make { get; set; }
    public String Model { get; set; }
    public int Year { get; set; }
}

public class CarService : DataService<Car>
{
    public IQueryable<Car> Cars
    {
        get
        {
            return (new List<Car> {
                new Car { VIN = "ABC123", Make = "Ford", Model = "F-250", Year = 2000 },
                new Car { VIN = "ABC124", Make = "BMW", Model = "Z-3", Year = 2005 },
                new Car { VIN = "ABC125", Make = "Audi", Model = "TT", Year = 2008 }
            }).AsQueryable();
        }
    }

    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
}

When access this service on the browser I get:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<service xml:base="http://localhost:60730/CarService.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">
  <workspace>
    <atom:title>Default</atom:title>
  </workspace开发者_如何学JAVA>
</service>

See that the collection didn't get listed. What am I doing wrong?


Try this instead:

[DataServiceKey("VIN")]
public class Car
{
    public String VIN { get; set; }
    public String Make { get; set; }
    public String Model { get; set; }
    public int Year { get; set; }
}

public class MyContainer
{
    public IQueryable<Car> Cars
    {
        get
        {
            return (new List<Car> {
                new Car { VIN = "ABC123", Make = "Ford", Model = "F-250", Year = 2000 },
                new Car { VIN = "ABC124", Make = "BMW", Model = "Z-3", Year = 2005 },
                new Car { VIN = "ABC125", Make = "Audi", Model = "TT", Year = 2008 }
            }).AsQueryable();
        }
    }
}

public class CarService : DataService<MyContainer>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜