Sta*_*hev 1 c# wpf wcf wcf-data-services
我用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.
Run Code Online (Sandbox Code Playgroud)
如果使用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; }
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
WCF数据服务(以及OData)不支持对原始类型或复杂类型的集合进行查询操作。服务操作不是IQueryable,而是IEnumerable。您可以向服务操作添加参数,以仅返回指定数量的结果。
在规范中,它是这样描述的:URI列表-URI13是返回原始类型集合的服务操作。 http://msdn.microsoft.com/zh-cn/library/dd541212(v=PROT.10).aspx 然后描述系统查询选项的页面:http : //msdn.microsoft.com/zh-cn/library /dd541320(v=PROT.10).aspx 在表格底部,描述了哪些查询选项可用于哪种uri类型。URI13仅允许$ format查询选项。
| 归档时间: |
|
| 查看次数: |
3194 次 |
| 最近记录: |