Serialize.Linq does not work in WCF proxy layer

2020-02-13 05:40发布

问题:

I use Serialize.Linq for send and receive Expression<Func<>> query between Client and Server in WCF Application service because Expression<Func<>> can not be serialized

all things seems ok BUT

when I add reference this library to wcf proxy layer and add server reference my web service

when build my project get errors like these

ExpressionNodeOfNewExpressionQsd8_SODT' does not implement inherited abstract member 'Serialize.Linq.Nodes.ExpressionNode.ToExpression(Serialize.Linq.ExpressionContext)'

ExpressionNodeOfTypeBinaryExpressionQsd8_SODT' does not implement inherited abstract member 'Serialize.Linq.Nodes.ExpressionNode.ToExpression(Serialize.Linq.ExpressionContext)'

etc ...

seems WCF create auto-generated proxy classes for this library instead of using main classes while I add reference Serialize.Linq assembly to proxy project but no help to solve my problem

You can test and show this problem very simply

like this

  1. Create Wcf Service Application and Add reference Serialize.Linq to project

    public interface IService1
    {
      [OperationContract(Name = "GetByPredicate")]
      List<Person> Get(ExpressionNode expression);
      [OperationContract]
      List<Person> Get();
    }
    
    
    public class Person
    {
      public int ID { get; set; }
      public string Name { get; set; }
    }
    
    public class Service1 : IService1
    {
      private List<Person> _persons;
      public Service1()
        {
        var p = new List<Person>
        {
            new Person() {ID = 1, Name = "A"},
            new Person() {ID = 2, Name = "B"},
            new Person() {ID = 3, Name = "C"},
            new Person() {ID = 4, Name = "D"},
            new Person() {ID = 5, Name = "E"},
            new Person() {ID = 6, Name = "F"},
            new Person() {ID = 7, Name = "G"},
            new Person() {ID = 8, Name = "H"}
        };
    
        _persons = p;
    }
    public List<Person> Get(ExpressionNode expression)
    {
        var ex = expression.ToExpression<Func<Person, bool>>().Compile();
        return _persons.Where(ex).ToList();
    }
    
    public List<Person> Get()
    {
        return _persons;
    }
    }
    
  2. Create Class Library Project and Add reference Serialize.Linq to project

  3. Add above Wcf Service as Service reference this this Class library as Wcf proxy project
  4. Now Build project , You can see errors !!! :(

Any Ideas ?!, How use Serialize.Linq library in proxy layer ?