I use an Entity Framework (edmx file) for my model, and I'm using WCF to access my model. When try to return list of an entity data model (example table object), i get an error:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
Here is my WCF code. IService.cs:
[ServiceContract(CallbackContract = typeof(IPesananCallBack), SessionMode = SessionMode.Required)]
public interface IPelayanWebService
{
[OperationContract]
List<table> GetAllTables();
}
Service.cs:
public List<table> GetAllTables()
{
TableModel model = new TableModel();
return model.GetAllTables();
}
My code in model:
public List<table> GetAllTables()
{
using (restoicdbEntities ent = new restoicdbEntities())
{
return ent.table.ToList();
}
}
in my client, I just call that function, and the error occured. Do I have to create my own data contract? Is there anyway to generate the datacontract from the edmx?
Update: This is the generated code from Entity Framework:
[EdmEntityTypeAttribute(NamespaceName="restoicdbModel", Name="table")]
[Serializable]
[DataContractAttribute(IsReference=true)]
public partial class table: EntityObject
{
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 ID_TABLE
{
get
{
return _ID_TABLE;
}
set
{
if (_ID_TABLE != value)
{
OnID_TABLEChanging(value);
ReportPropertyChanging("ID_TABLE");
ID_TABLE = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ID_TABLE");
OnID_TABLEChanged();
}
}
}
private global::System.Int32 ID_TABLE;
partial void OnID_TABLEChanging(global::System.Int32 value);
partial void OnID_TABLEChanged();
}
After reading the link provided by Steve Wilkes, WCF, Entity Framework & Data Contracts , it looks like it is not good to pass entity object from web service. So I have to create my own Data Transfer Object which is a mapping from the entity object, then pass it from the web service.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.