为什么 System.Data.Services.MimeTypeAttribute 现在只是类级别属性?

发布于 2024-08-28 05:23:58 字数 1541 浏览 6 评论 0原文

我正在开始使用 Astoria/ADO.NET 数据服务/WCF 数据服务。查看大量代码示例后,发现 MimeType 属性曾经是方法级属性。安装最新版本后更新,它现在是一个类级别属性。

如果我有多个服务操作想要作为某种 MimeType 返回,那么现在看来我必须为每个操作创建一个新服务。这是正确的吗?


大多数示例是这样的:

[WebGet]
[SingleResult]
[MimeType("application/pdf")]
public IQueryable<byte[]> FooPDF()
{
    var result = from p in this.CurrentDataSource.MyPDFs
                 where p.FooID == 2
                 select p;

    return result.Take(1).Select(p => p.PDF);
}

我得到“属性‘MimeType’在此声明类型上无效。它仅在‘类’声明上有效。”当我编译时,因为现在我不能这样做。


现在,我必须这样做:

[MimeType("FooPDF", "application/pdf")]
public class FooService : DataService<FooDBEntities>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetServiceOperationAccessRule("FooPDF", ServiceOperationRights.All);
    }

    [WebGet]
    [SingleResult]
    public IQueryable<byte[]> FooPDF()
    {
        var result = from p in this.CurrentDataSource.MyPDFs
                     where p.FooID == 2
                     select p;

        return result.Take(1).Select(p => p.PDF);
    }
}

更糟糕的是我无法向我的类添加重复的 MimeType 属性。

这一切真的是设计的< /a>,或者我错过了什么?

I'm getting started with Astoria/ADO.NET Data Services/WCF Data Services. Looking through a lot of the code samples out there, it appears that the MimeType attribute used to be a method level attribute. After installing the latest update, it is now a class level attribute.

If I have more than one Service Operation that I want to return as a certain MimeType, then it appears now that I have to create a new service for each operation. Is this correct?


Most examples are like this:

[WebGet]
[SingleResult]
[MimeType("application/pdf")]
public IQueryable<byte[]> FooPDF()
{
    var result = from p in this.CurrentDataSource.MyPDFs
                 where p.FooID == 2
                 select p;

    return result.Take(1).Select(p => p.PDF);
}

I get "Attribute 'MimeType' is not valid on this declaration type. It is only valid on 'class' declarations." when I compile, because now I can't do this.


Now, I have to do this:

[MimeType("FooPDF", "application/pdf")]
public class FooService : DataService<FooDBEntities>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetServiceOperationAccessRule("FooPDF", ServiceOperationRights.All);
    }

    [WebGet]
    [SingleResult]
    public IQueryable<byte[]> FooPDF()
    {
        var result = from p in this.CurrentDataSource.MyPDFs
                     where p.FooID == 2
                     select p;

        return result.Take(1).Select(p => p.PDF);
    }
}

What's worse is that I can't add duplicate MimeType attributes to my class.

Is all of this really by design, or am I missing something?

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

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

发布评论

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

评论(1

横笛休吹塞上声 2024-09-04 05:23:58

感谢您向我们报告此错误。我在最后打开了这个问题来跟踪这个问题。

在最近的更新中,我们添加了对 blob 的支持,作为数据服务中的一流概念。如果您与某个实体有 blob 关联,那么服务器和客户端都有办法显示它。要了解更多信息,请参阅以下链接: http://msdn.microsoft.com/en-us/library/ee473426(v=VS.100).aspx

希望这会有所帮助。

谢谢
普拉蒂克
[微软金融时报]

Thanks for reporting this bug to us. I have opened this at our end to track this issue

With the recent update, we added the support for blobs as a first class concept in the data services. If you have a blob association with an entity, then both server and client have ways to surface this. To know more about this, please refer to the following link: http://msdn.microsoft.com/en-us/library/ee473426(v=VS.100).aspx

Hope this helps.

Thanks
Pratik
[MSFT]

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