【发布时间】:2012-01-09 18:01:07
【问题描述】:
我创建了一个非常简单的 .NET 4.0 Web 项目,带有 WPF 客户端。
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);
}
}
【问题讨论】:
标签: c# wpf wcf wcf-data-services