2010-04-28 20 views
1

我最近開始製作一個示例項目,以處理來自RIA服務的oData源。我可以通過任何Web瀏覽器查看供稿和元數據,但是,如果我嘗試對供稿執行某些查詢操作,則會收到「不受支持」的例外。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(); 
    } 
} 

如果我提供的網址「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) 

回答

相關問題