c# - Implementing wcf with mvc4 entity framework fails invoking method -
i have wcf application in have used entitity framework , have implemented dbcontext querying database. when view svc file in browser exposes operations.
i have interface class this:
[servicecontract] public interface iservice1 { [operationcontract] list<booksmodels> getbookslist(); [operationcontract] booksmodels getbook(int id); }
i have implementation in svc.cs file
public list<booksmodels> getbookslist() { mvcentity en = new mvcentity(); return en.book.tolist(); } public int getbookid(int id) { //return db.book.find(id); return 1; }
and booksmodels class this
[datacontract] public class booksmodels { [key] [datamember] public int bookid { get; set; } [datamember] public string bookname{get;set;} }
and have config file default 1 created when creating wcf service application .
but when invoke getbookslist service mvc wcf client gives me following error:
failed invoke service. possible causes: service offline or inaccessible; client-side configuration not match proxy; existing proxy invalid. refer stack trace more detail. can try recover starting new proxy, restoring default configuration, or refreshing service.
but when invoke second method returns 1.
i examined when service uses dbcontext return data gives error , fine when not.
i have gone through various blogs , questions in stackoverflow didn't help. how can problem addressed. thanks
i think it's problem of serialization. make serialisation test you're business layer take list entity framework , serialize deserialize , compare before , after serialization.
use datacontractserializer :
datacontractserializer serialiser = new datacontractserializer(typeof(list<booksmodels>)); list<booksmodels> expected = business.getbookslist(); stream stream = new memorystream(); serialiser.writeobject(stream, expected); stream.position = 0; list<booksmodels> actual = serialiser.readobject(stream) list<booksmodels>; assert.isnotnull(actual); assert.areequal(expected.prop1, actual.prop1); assert.areequal(expected.prop2, actual.prop2); // ... //
if doesn't work use proxy in entity framework. turn off proxy :
context.contextoptions.proxycreationenabled = false;
Comments
Post a Comment