为什么我的 WCF 数据服务集合没有列出?

发布于 2024-11-27 08:41:29 字数 1470 浏览 1 评论 0原文

我正在尝试制作一个简单的 WCF 数据服务。我能够成功访问 scv 文件,但我的 Cars 收藏未列出。我的 scv 的内容是:

[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;
    }
}

当在浏览器上访问此服务时,我得到:

<?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>
</service>

看到该集合没有列出。我做错了什么?

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>
</service>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢好甜 2024-12-04 08:41:29

试试这个:

[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;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文