2012-01-09 11 views
1

私は非常に単純な.NET 4.0 WebプロジェクトをWPFクライアントとともに作成しました。要求されたリソースにクエリオプションを適用することはできません

ウェブソリューションには、IQueryable<string>を返すサービス操作を持つWCFデータサービスがあります。

WPFクライアントはそのサービスを参照し、直接クエリでCreateQuery().Take()を使用してサービス操作を呼び出します。

は残念ながら、私は、次のエラーメッセージが表示されます。

Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource. 

私はhttp://localhost:20789/WcfDataService1.svc/GetStrings()?$top=3を使用してブラウザでサービスを表示すると、私は同じエラーを取得します。

アイデア?ソリューションをどこかにアップロードする必要があるかどうかを教えてください。

ありがとうございます!

WcfDataService1.svc.cs:

namespace WPFTestApplication1 
{ 
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] 
    public class WcfDataService1 : DataService<DummyDataSource> 
    { 
     public static void InitializeService(DataServiceConfiguration config) 
     { 
      config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); 
      config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); 
      config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; 
     } 

     [WebGet] 
     public IQueryable<string> GetStrings() 
     { 
      var strings = new string[] 
      { 
      "aa", 
      "bb", 
      "cc", 
      "dd", 
      "ee", 
      "ff", 
      "gg", 
      "hh", 
      "ii", 
      "jj", 
      "kk", 
      "ll" 
      }; 
      var queryableStrings = strings.AsQueryable(); 
      return queryableStrings; 
     } 
    } 

    public class DummyEntity 
    { 
     public int ID { get; set; } 
    } 

    public class DummyDataSource 
    { 
     //dummy source, just to have WcfDataService1 working 
     public IQueryable<DummyEntity> Entities { get; set; } 
    } 
} 

MainWindow.xaml.cs:(WPF)

public MainWindow() 
    { 
     InitializeComponent(); 

     ServiceReference1.DummyDataSource ds = new ServiceReference1.DummyDataSource(new Uri("http://localhost:20789/WcfDataService1.svc/")); 
     var strings = ds.CreateQuery<string>("GetStrings").Take(3); 

     //exception occurs here, on enumeration 
     foreach (var str in strings) 
     { 
      MessageBox.Show(str); 
     } 
    } 

答えて

4

WCF Data Servicesの(とのOData同様)をサポートしていません。プリミティブ型または複合型のコレクションに対するクエリ操作。サービス操作はIQueryableとしては見られませんが、IEnumerableと同じです。 サービス操作にパラメータを追加して、指定した数の結果のみを返すことができます。

仕様では、次のように記述されています。 URIのリスト - URI13はプリミティブ型のコレクションを返すサービス操作です。 http://msdn.microsoft.com/en-us/library/dd541212(v=PROT.10).aspx 次に、システムクエリオプションを説明するページ: http://msdn.microsoft.com/en-us/library/dd541320(v=PROT.10).aspx 下の表では、どの種類のクエリオプションをどのuriタイプに使用できるかについて説明しています。 URI13は、$形式のクエリオプションのみを許可します。

+0

ありがとうございます!これについての参考情報はありますか?答えに追加することはできますか? –

+0

仕様を参照して応答を更新しました。 –

関連する問題