How to expose a web method with Func parameter?
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())
开发者_Python百科 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!
You cannot serialize your own code like this. Where should the serializer start and where stop? Should it transfer only the code of your method and all assemblies that are called from within the method? LINQ to objects does something similar. You should have a look at Expressions. These can be serialized across the wire.
No can do. If you think of the func parameter as a reference to some code on the caller's side, how do you expect the server to be able to see that code?
i think you might not be able to implement client callbacks with classical asp.net web services. you can opt for WCF for this. KickStart.
精彩评论