ADO.NET Entity Framework on Vs2012 + WCF = Error -


first of all, reading question.

i developing solution using vs 2012 using ado.net entity framework (5 think, latest version). working fine until introduce wcf service business layer (this assignment school, cannot scrap wcf business layer).

the issue when request data database. when have method returns string database, works fine (since primitive). when returns entity object (such account), goes hell.

exception: (yeah, vague).

an error occurred while receiving http response http://localhost:8733/services/accountsmanager. due service endpoint binding not using http protocol. due http request context being aborted server (possibly due service shutting down). see server logs more details.

what tried: tried modifying entites.tt file add [datacontract] [datamember] attribute. because in older versions of ef, seemed doing on own. not know if neccessary since allows me compile , not complain not serializable.

this how looks @ first:

namespace commonlayer { using system; using system.collections.generic;   public partial class account {     public account()     {         this.transactions = new hashset<transaction>();         this.transactions1 = new hashset<transaction>();     }      public system.guid id { get; set; }     public int type { get; set; }     public string name { get; set; }     public int currency { get; set; }     public decimal balance { get; set; }     public system.datetime dateopened { get; set; }     public nullable<int> duration { get; set; }     public string username { get; set; }      public virtual accounttype accounttype { get; set; }     public virtual currency currency1 { get; set; }     public virtual user user { get; set; }     public virtual icollection<transaction> transactions { get; set; }     public virtual icollection<transaction> transactions1 { get; set; } } } 

how looks after modification:

namespace commonlayer { using system; using system.collections.generic; using system.runtime.serialization; [datacontract] public partial class account {     public account()     {         this.transactions = new hashset<transaction>();         this.transactions1 = new hashset<transaction>();     }      [datamember] public system.guid id { get; set; }     [datamember] public int type { get; set; }     [datamember] public string name { get; set; }     [datamember] public int currency { get; set; }     [datamember] public decimal balance { get; set; }     [datamember] public system.datetime dateopened { get; set; }     [datamember] public nullable<int> duration { get; set; }     [datamember] public string username { get; set; }      public virtual accounttype accounttype { get; set; }     public virtual currency currency1 { get; set; }     public virtual user user { get; set; }     public virtual icollection<transaction> transactions { get; set; }     public virtual icollection<transaction> transactions1 { get; set; } } } 

any pointers appreciated.

my wcf class

using system; using system.collections.generic; using system.linq; using system.servicemodel; using system.text; using system.threading.tasks;  namespace businesslayer {      [servicecontract]     interface iaccountsmanager     {         [operationcontract]         list<commonlayer.account> getaccounts(string username);          [operationcontract]         string getdata();          [operationcontract]         commonlayer.account getaccount(string username);     }      class accountsmanager: iaccountsmanager, idisposable     {         public list<commonlayer.account> getaccounts(string username)         {             return datalayer.accountsrepository.instance.getaccountlist(username).tolist();         }          public string getdata()         {             commonlayer.account acc  = this.getaccounts("test").firstordefault();             return acc.dateopened.tostring();         }          public commonlayer.account getaccount(string username)         {             return this.getaccounts(username).firstordefault();         }          public void dispose()         {             datalayer.accountsrepository.reset();         }     } } 

you need use dto (data transfer object) , map ef object dto.

so service might accept object called mydto looking like:

[datacontract] public class mydto {     [datamember]     public int id {get;set;} } 

and static mapping class methods

public static myentity map(mydto dto) {     return new myentity { id = dto.id }; }  public static mydto map(myentity entity) {     return new mydto { id = entity.id }; } 

you can map required service can use dto , entity framework can use entity.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -