1

我最近开始设计一个示例项目来使用来自 RIA 服务的 oData 提要。我可以通过任何网络浏览器查看提要和元数据,但是,如果我尝试对提要执行某些查询操作,我会收到“不受支持”的异常。

示例 oData 提要:

<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<feed 
  xml:base="http://localhost:50880/Services/
              Rebirth-Web-Services-ProductService.svc/OData/" 
  xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
  xmlns="http://www.w3.org/2005/Atom">
  <title type="text">ProductSet</title>
  <id>http://localhost:50880/Services/
              Rebirth-Web-Services-ProductService.svc/OData/ProductSet/</id>
  <updated>2010-04-28T14:02:10Z</updated>
  <link rel="self" title="ProductSet" href="ProductSet" />
  <entry>
    <id>http://localhost:50880/Services/
             Rebirth-Web-Services-ProductService.svc/OData/ProductSet
                  (guid'b0a2b170-c6df-441f-ae2a-74dd19901128')</id>
    <title type="text"></title>
    <updated>2010-04-28T14:02:10Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="Product" 
      href="ProductSet(guid'b0a2b170-c6df-441f-ae2a-74dd19901128')" />
    <category term="Rebirth.Web.Models.Product" 
      scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:Id m:type="Edm.Guid">b0a2b170-c6df-441f-ae2a-74dd19901128</d:Id>
        <d:Name>Product 0</d:Name>
        <d:ProductType>Type 1</d:ProductType>
        <d:Status>Active</d:Status>
      </m:properties>
    </content>
  </entry>

示例 web.config 条目:

<add name="OData"
  type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory,                   
  System.ServiceModel.DomainServices.Hosting.OData, 
  Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

样品服务:

[EnableClientAccess()]
public class ProductService : DomainService {      
    [Query(IsDefault = true)]     
    public IQueryable<Product> GetProducts() {
        IList<Product> products = new List<Product>();

        for (int i = 0; i < 90; i++) {                
            Product product = new Product {
                Id = Guid.NewGuid(),
                Name = "Product " + i.ToString(),
                ProductType = i < 30 ? "Type 1" :
                   ((i > 30 && i < 60) ? "Type 2" : "Type 3"),
                Status = i % 2 == 0 ? "Active" : "NotActive"
            };

            products.Add(product);
        }

        return products.AsQueryable();
    }
}

如果我向我的网络浏览器提供 URL“ http://localhost:50880/Services/Rebirth-Web-Services-ProductService.svc/OData/ProductSet(guid 'b0a2b170-c6df-441f-ae2a-74dd19901128')”我会收到以下xml:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code/>
  <message xml:lang="en-US" 
    xmlns:xml="http://www.w3.org/XML/1998/namespace">
    Requests that attempt to access a single element using key values 
    from a result set are not supported.
  </message>
</error>

我是 RIA 和 oData 的新手。这可能像我的网络浏览器不支持对结果集或其他类型的查询一样简单吗?

编辑:这是我在 LinqPad 中看到的:

Member qRuntimeMethodInfo 
QueryResult.Execute () 

StackTrace    
  at System.Data.Services.Client.QueryResult.Execute()
  at System.Data.Services.Client.DataServiceRequest.Execute[TElement]
      (DataServiceContext context, QueryComponents queryComponents)  
4

1 回答 1

0

Refer here: RIA Services OData "Query options are not allowed." It still not implemented in 2010 SP1. Just checked.

于 2011-03-14T13:33:19.107 回答