When I retrieve all orders and their OrderDetails from ASP.NET MVC through WCF it throws error. till service it works fine, only when the call reaches out of service in this case MVC, it throws error:
The underlying connection was closed: The connection was closed unexpectedly.
-
I am not using lazy loading
-
I want to use same POCO class, don’t want separate create DataContract in WCF.
My code:
public class HomeController : Controller
{
public ActionResult Index()
{
ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
var allOrders = service.GetAllOrders();
service.Abort();
return View();
}
}
// WCF Service Method
public List<Order> GetAllOrders()
{
List<Order> orders = null;
using (NorthwindEntities context = new NorthwindEntities())
{
orders = context.Set<Order>().Include("Order_Details").AsEnumerable().ToList();
}
return orders;
}
public class Order
{
public Order()
{
this.Order_Details = new HashSet<Order_Detail>();
}
public virtual ICollection<Order_Detail> Order_Details { get; set; }
}
public class Order_Detail
{
public int OrderID { get; set; }
public int ProductID { get; set; }
public decimal UnitPrice { get; set; }
public short Quantity { get; set; }
public float Discount { get; set; }
}
thanks to Alex,
it works after disabling ProxyCreationEnabled.