我用WPF客戶端創建了一個非常簡單的.NET 4.0 Web項目。查詢選項無法應用於請求的資源
Web解決方案有一個WCF數據服務,服務操作返回IQueryable<string>
。
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);
}
}
謝謝!你有沒有這方面的參考,所以我們可以將它添加到答案? – 2012-01-10 19:41:45
參考規範更新了回覆。 – 2012-01-11 08:01:17