我最近开始编写一个示例项目来使用来自RIA服务的oData feed。我可以通过任何网络浏览器查看Feed和元数据,但是,如果我尝试对Feed执行某些查询操作,则会收到“不支持”的例外情况。
示例oData feed:
<?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();
}
}
如果我提供网址“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)
答案 0 :(得分:0)
请参阅此处:RIA Services OData "Query options are not allowed." 它仍然没有在2010 SP1中实现。刚检查过。