1

I wonder if I could expose a web method with Func parameter!

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

When I tried to update the web reference I had an exception from Visual Studio that:

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

Any workaround please!

4

3 回答 3

4

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

于 2011-04-25T10:23:50.347 回答
2

没办法。如果您将 func 参数视为对调用方某些代码的引用,您希望服务器如何能够看到该代码?

于 2011-04-25T10:47:55.857 回答
1

我认为您可能无法使用经典的 asp.net Web 服务实现客户端回调。您可以为此选择 WCF。启动

于 2011-04-25T10:41:37.140 回答