-1

I call the method LeerAlerta(), which I want to return the list of rows from a simple query.

This is the method that makes the query in Linq:

internal List<alertas> LeerAlerta()

{
    using (var db = new alertas2015())
    {
        var alertas = db.alertas.ToList();

        return alertas;
    }
}

This is the operation Contract:

[OperationContract]
List<alertas> LeerAlerta();

And this is the object alertas:

public partial class alertas
{
    public int id { get; set; }
    public int modulos_id { get; set; }
    public string proceso { get; set; }
    public string metodo { get; set; }
    public string descripcion { get; set; }
    public int estado { get; set; }
    public string receptor { get; set; }
    public System.DateTime fecha { get; set; }
    public System.DateTime fecha_aceptada { get; set; }

    public virtual modulos modulos { get; set; }
}

When I call LeerAlertas it just stops connection and:

System.Runtime.Serialization.SerializationException is all i'm getting from tracing it.

The message:

No se espera el tipo 'System.Data.Entity.DynamicProxies.alertas_7895CEE569AEBE6977614A1873DB1D304F0CEC3F6B5A87E3B3C324BA933840CA' con el nombre de contrato de datos 'alertas_7895CEE569AEBE6977614A1873DB1D304F0CEC3F6B5A87E3B3C324BA933840CA:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies'. Intente usar DataContractResolver o agregar tipos no conocidos estáticamente a la lista de tipos conocidos (por ejemplo, usando el atributo KnownTypeAttribute o agregándolos a la lista de tipos conocidos que se pasa a DataContractSerializer).

I have 0 experience in serializing objects so I don't realy know how to fix this problem.

Catalufo
  • 33
  • 1
  • 8
  • _"it just stops connection and doesn't return nothing"_ - that never happens. [Check WCF Tracing to find the actual error](http://stackoverflow.com/questions/4271517/how-to-turn-on-wcf-tracing). My guess: you have [lazy loading and a cyclic dependency](http://stackoverflow.com/questions/6291094/wcf-error-serializing-cycle-reference), causing `alertas.modulos.alertas.modulos` and so on. See also [Problems with the WCF Datacontract serialization of circular reference in Entity Framework](http://stackoverflow.com/questions/10160881/) and so on. – CodeCaster Jun 03 '15 at 09:40
  • The service doesn't have connection or it's unreachable. That's the error I'm getting if using LIST, if using a normal bool or string or int it's working fine, it's working fine with other methods i have but with LIST is not working. – Catalufo Jun 03 '15 at 09:42
  • Again, that is not the issue. That is not what happens. What most likely is happening is that the service encounters an exception while serializing the response, after which it closes the connection and your client gives a nondescript error message. Again, enable WCF Tracing, see links in my previous comment. – CodeCaster Jun 03 '15 at 09:43
  • I have tracing now and looked at the file but still getting same "supposed error", can't get this fixed :( – Catalufo Jun 03 '15 at 09:51
  • Tracing won't solve the error for you, it will point out where it occurs. – CodeCaster Jun 03 '15 at 09:52
  • I guess it has to be: System.Runtime.Serialization.SerializationException, but i don't know how to fix that – Catalufo Jun 03 '15 at 09:53
  • Yes, that's it. Try putting the actual message of the exception in your favorite web search engine. Or include it in your question and share what you have tried. Try to understand the issue. – CodeCaster Jun 03 '15 at 09:55
  • The trace viewer will show you the _full_ exception. With just "serializationexception" you can't research anything. **Read** the exception message and handle accordingly. – CodeCaster Jun 03 '15 at 10:08
  • It's so long that any of my favorite web search engines is capable of finding answers, i have to scroll down for 2 seconds with the exception, no way to find a clue of the exact error – Catalufo Jun 03 '15 at 10:11
  • http://stackoverflow.com/questions/3372895/datacontractserializer-error-using-entity-framework-4-0-with-wcf-4-0 – CodeCaster Jun 03 '15 at 10:13

3 Answers3

0

The answer was as @CodeCaster told me, put in dbcontext the next thing:

Configuration.ProxyCreationEnabled = false;

Catalufo
  • 33
  • 1
  • 8
0

I had encounter the same kinda problem when creating a WCF Service for BLAZE Advisor Rules and couldn't find a cause for the same. Then I tried applying [Serializable()] attribute to my classes in model which is just huge.

Give it a try and check if the same works for you. I'm not sure this is going to be exact solution. But a try if works out is better than not to try.

Happy Service Coding!!!

Akif Patel - BRMS
  • 537
  • 1
  • 4
  • 13
-1

I think you can try with [DataContract] attribute on class alertas

Mitan Shah
  • 344
  • 2
  • 9
  • I think you need to try to understand the problem before answering, then research whether your answer is actually correct. The DataContract attribute is not required since a few years already. See http://stackoverflow.com/questions/4836683/when-to-use-datacontract-and-datamember-attributes. – CodeCaster Jun 03 '15 at 10:27