gpt4 book ai didi

c# - 如何公开带有 Func 参数的 Web 方法?

转载 作者:太空宇宙 更新时间:2023-11-03 18:44:13 24 4
gpt4 key购买 nike

我想知道我是否可以使用 Func 参数公开一个 web 方法!

[WebMethod]
public List<Entity> ReadEntities(Func<Entity, bool> predicate)
{
using (var entities = new GwEntities())
return entities.Entities.Where(predicate).ToList();
}

当我尝试更新 Web 引用时,Visual Studio 出现异常:

System.Func[GwModel.Entity,SystemBoolean] caonnot be serialized because it does not have a parameterless constructor

请有任何解决方法!

最佳答案

你不能像这样序列化你自己的代码。序列化程序应该从哪里开始,在哪里停止?它是否应该仅传输您的方法的代码以及从该方法中调用的所有程序集? LINQ to objects 做类似的事情。你应该看看Expressions .这些可以通过网络进行序列化。

关于c# - 如何公开带有 Func 参数的 Web 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5777331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com