none
Time excedeed in some cases when the service return the result of the entity framwork with POCO entities RRS feed

  • Question

  • I have prepared my POCO entities as is described here:

    https://msdn.microsoft.com/en-us/library/ee853286%28v=vs.100%29.aspx

    The service use entity framework to get the data and return a list with the results. But with some elements make that the service is halt and receive an error that says that I have exceeded the time of the reliable session.

    Entity framwork when returns results, with the navigation properties, entity A has to a reference to the entity B and B to A with its navigation property.

    With this entites that has problems, if I clear the collection of a navigation property, or set to null, I break the reference cycle and the there is no problem. But this is not a solution, because I want to keep this references, and also it would make me, in the service, to modify all the resutls that I get from entity framework to break the cycles. And really I don't know if this is a general solution or only in this case.

    Really i can't isolate the problem completely.

    Thanks so much.

    EDIT: I have added a loink to a project in VS2015 that can reproduce the problem.

    Just run the solution. The main project is a simple WPF application that has a button that request the data to the service and it would show the results in the datagrid. The datagrid only has the interest to now if the data is received from the service or not.

    In the service, I have a for that creates 300 objects and try so send to the proxy in the client, but the application is blocked. With 275 it works.

    The object is a POCO entity that has 4 properties, long type, so there is not a hugh amount of data, because is 8 * 4 * 300 = 9600bytes.

    The link to the project is this:

    https://onedrive.live.com/redir?resid=74F66A9BB4A4DE24!140&authkey=!AK-z7HnPiU4pO5o&ithint=file%2czip

    It seems that OneDrive does not work, here I have another link:

    

    Thanks so much.





    Tuesday, December 15, 2015 7:56 PM

All replies

  • Hi ComptonAlvaro,

    Could you provide the more detailed error message or screenshot and some related code?

    It will help us to reproduce your problem. As far as I know, when we use Entity Framework

    with WCF which used navigation, it will cause the service stop.

    Because the Entity Framework has a default setting. It will generate the proxy class

    automatically.For example, I have  entity A and  entity B,  entity A has a navigation to B,

    then Entity Framework will generate the proxy for class A. So when we use the WCF to

    serialize the class A ,It will cause theexception. Because WCF can't serialize the proxy

    class A which generate by Entity Framework. 

    How to solve this issue:

    As far as I know, we can set the this.Configuration.ProxyCreationEnabled = false in

    Context.cs file which generate by Entity Framework.

    Like below:

    public partial class myDatabaseEntities : DbContext
        {
            public myDatabaseEntities()
                : base("name=myDatabaseEntities")
            {
                this.Configuration.ProxyCreationEnabled = false;
            }
        } 

    If I miss understand the issue wrong, please let me know.

    I hope that will be helpful to you.

    Best Regards,
    Wanjun Dong.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    Thursday, December 17, 2015 8:29 AM
    Moderator
  • Hello:

    Thanks for your reply.

    Right, I known the problem with the proxies entities and in this test I had disabled the creation of the proxies. So this does not solve the problem in this case, but it is true that I need to disabled if I want to work with EF and WCF.

    I have done more tests, and I have realized that if i don't make includes to populate the navigation properties of the main object TypeA, and return the first 117 elements, I get the error, but if I return the first  116 elements it works.

    I have tried excluding the element in the position 116, which has the ID = XXX, so in the query of EF I exlcude this ID of the results and the behavior is the same, if I return the first 116 elements works fine and if I return 117 elements I get the error.

    I will try to simplyfy my code and I will post, but I am asking my self if it is possible that 117 takes so many time to be serializable, but the POCO entity has only 15 properties (including the navigation properties).

    Thanks.

    EDIT: it seems that there is not relation with EF, because I have created in a for loop 150 entities of this type in my service, ignoring the result that I get from EF and the problem is the same. So it seems that the problem is not EF nor the navigation properties.

    I will prepare a simple example that reproduce the problem.



    Thursday, December 17, 2015 12:23 PM
  • Hello:

    I have added a link to a project that reproduce the problem.

    Thursday, December 17, 2015 10:24 PM
  • I use EF behind WCF services all the time. I use DB first always with DTO in a List<T>. I have never faced the problem you are facing.
    Thursday, December 17, 2015 10:36 PM
  • Thanks, DA924, as you say, the problem is no EF, because I have done tests without use EF behind WCF and the problem is the same. I guess it seems something related with the configuration of WCF but I don't see any possible problem.

    I have upload a project to OneDrive, you can find it in the first post, that reproduces the problem.

    Thanks.

    Friday, December 18, 2015 8:11 AM
  • Hi

    Perhaps you can try set the tracing file in your web.config file.

    like this:

    <system.diagnostics>
    <sources>
    <source name="System.ServiceModel"
    switchValue="Information, ActivityTracing">
    <listeners>
    <add name="log"
    type="System.Diagnostics.XmlWriterTraceListener"
    initializeData="c:\Traces.svclog" />
    </listeners>
    </source>
    </sources>
    </system.diagnostics>

    please refer:

    1.Configuring Tracing

    regards,

    vince

    Thursday, December 24, 2015 10:25 AM