2

I have developed WCF service which is internally using Entity framework for Database operation. While Insert, Update and Delete is working fine I am facing issue while selection of all records from that table and exposing it to client.

My Code to Expose Data to client is :-

public IQueryable <Bank_Configuration>  SelectBankConfiguration()
        {
            using (EFEntities objEFEntities = new EFEntities())
            {                             
                var Result= from c in objEFEntities.Bank_Configuration 
                            select c;

                return Result;
            }            

        }

But at client end when I use this method to get data client is giving Error as An error occurred while receiving the HTTP response to "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/." This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Why this error and how to expose data to client

4

1 に答える 1

2

EFEntities オブジェクトは、WCF メッセージがシリアル化される前に破棄されます。これにより、EF クエリが実際に実行されます。ToList() または ToArray() を呼び出して、"using" ブロック内で結果セットを具体化します。

public IEnumerable<Bank_Configuration>  SelectBankConfiguration()
{
    using (EFEntities objEFEntities = new EFEntities())
    {                             
        var Result= from c in objEFEntities.Bank_Configuration 
                    select c;

        return Result.ToArray();
    }            

}
于 2013-01-09T19:11:07.483 に答える