开发者

RIA Service/oData ... "Requests that attempt to access a single element using key values from a result set are not supported."

开发者 https://www.devze.com 2022-12-28 06:24 出处:网络
I\'ve recently started working up a sample project to play with an oData feed coming from a RIA service. I am able to view the feed and the metadata via any web browser, however, if I try to perform c

I've recently started working up a sample project to play with an oData feed coming from a RIA service. I am able to view the feed and the metadata via any web browser, however, if I try to perform certain query operations on the feed I receive "unsupported" exceptions.

Sample 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:prope开发者_如何学JAVArties>
        <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>

Sample web.config entry:

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

Sample service:

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

If I provide the url "http://localhost:50880/Services/Rebirth-Web-Services-ProductService.svc/OData/ProductSet(guid'b0a2b170-c6df-441f-ae2a-74dd19901128')" to my web browser I receive the following 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>

I'm new to RIA and oData. Could this be something as simple as my web browsers not supporting this type of querying on the result set or something else?

EDIT: This is what I see in 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)  


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

0

精彩评论

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