根据wcf返回自定义查询的信息列表 [英] Returns a list of information in terms of custom queries by wcf
问题描述
我想要一个带有Web服务实现的WCF Web服务,该服务返回自定义查询方面的信息列表但是第二个图像中出现错误请检查提示方面
< img src =http://i.stack.imgur.com/VlY3m.pngstyle =width:500; height:350;/>
< ; img src =http://i.stack.imgur.com/1c0Ii.pngstyle =width:500; height:350;/>
我尝试过:
我想要一个带有Web服务实现的WCF Web服务,它返回一个信息列表自定义查询但错误在第二张图片中运行请检查提示
I want a WCF web services with the Web services implementation that returns a list of information in terms of custom queries But an error runs in the Second image Please check tips with respect
<img src="http://i.stack.imgur.com/VlY3m.png" style="width:500;height:350;"/>
<img src="http://i.stack.imgur.com/1c0Ii.png" style="width:500;height:350;"/>
What I have tried:
I want a WCF web services with the Web services implementation that returns a list of information in terms of custom queries But an error runs in the Second image Please check tips with respect
推荐答案
您正在尝试序列化一个委托(Func< >
参数).NET默认值不支持。有办法解决这个问题:
1)匿名方法序列化 [ ^ ]):仅当您的委托不关闭局部变量且不包含其他非序列化对象(例如表达式树)时才有效。 (未经我测试。)
2) InterLINQ [ ^ ]:允许您序列化表达式树。实际的实现将整个查询过程抽象到WCF上,好像EF-DbContext在客户端可用。 (我成功使用它,但不是用EF。)
3)不漂亮,但唯一的选择是如果选项1不适合你和你回避选项2:不是以委托的形式表达你的查询谓词,而是用简单的参数或包含查询参数的类表达它 - 然后从中构建查询服务器端。
You're attempting to serialize a delegate (thatFunc<>
parameter) which isn't supported by .NET defaults. There are ways to get around that:
1) Anonymous Method Serialization[^]) : Only works if your delegate doesn't close over local variables and doesn't include other, non-serializable objects (e.g. an expression tree). (Not tested by me.)
2) InterLINQ[^] : Lets you serialize an expression tree, in general. The actual implementation abstracts the whole querying-process over WCF away, as if the EF-DbContext was available at the client. (I'm using it successfully, not with EF though.)
3) Not pretty, but the only alternative if option 1 doesn't work for you and you shy away from option 2: Instead of expressing your query-predicate in form of a delegate, express it with simple parameters or a class that holds the query parameters - and then build the query server-side from that.
这篇关于根据wcf返回自定义查询的信息列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!