An existing connection was forcibly closed by the remote host

I got below error when I try to fetch information from database using WCF service. I was using model entities directly because of this my code not able to fetch data. So I used following technic and it worked well. Basically we need to use DTOs to do data serialization.

use DTOs (Data Transfer Objects), this is an example of how Newspaper class could be:

public class NewspaperDTO
    public NewspaperDTO(Newspaper newspaper)
        this.Name = newspaper.Name;
        this.Image = newspaper.Image;
        this.Link = newspaper.Link;
        this.Encoding = newspaper.Encoding;

    public string Name { get; set; }

    public string Image { get; set; }

    public string Link { get; set; }

    public string Encoding { get; set; }

And then in your service:

public List<NewspaperDTO> GetNews()
    return entities.Newspapers.Select(a => new NewspaperDTO(a)).ToList();

MVC Project from github


## EmployeeManagement Demo Application
This repository contains a multi-layer application which was built for demonstration purposes.
It contains a collection of patterns and services which are used in enterprise applications.
– Layered architecture
– Dependency injection using AutoFac
– Test-driven design
– EntityFramework code-first database context
– UnitOfWork and repository pattern
– Restful WCF service with JSON
– Diverse client technologies. Using DTOs to exchange information with the backend and ViewModels (MVVM) to bind model data to views.

Furthermore, the aim of this project was to show the interplay of the mentioned technologies, principles and practices.

### Missing points
– Authentication and authorization
– Cross-platform mobile clients
– Localization
– Input validation
– Filtering, grouping, sorting, paging of list items

### Helpful links

Generic repository pattern, unit of work, entity framework in MVC

Autofac for MVC

Autofac for WebApi

Using Web API 2 with Entity Framework 6

Dependency Injection in ASP.NET Web API 2

Exception Handling in ASP.NET Web API

Automated Testing of ASP.NET Web API and MVC applications

Creating WCF REST services

Using MVVMLight in a WPF application

Configuring Relationships with the Fluent API

ASP.NET Web API Exception Handling


Exception Handling in WebAPI

Consuming WCF Services in Xamarin–part-1.aspx–part-2.aspx

Custom WCF message formatters (NewtonsoftJsonBehavior)

How to add a second css class with a conditional value in razor MVC 4

Your answer (assuming this works, I haven’t tried this):

<div class="details @(@Model.Details.Count > 0 ? "show" : "hide")">

Second option:

@if (Model.Details.Count > 0) {
    <div class="details show">
else {
    <div class="details hide">

Third option:

<div class="@("details " + (Model.Details.Count>0 ? "show" : "hide"))">

Binding arrays in ASP.NET MVC without index?

You don’t need to explicitly index flat data. If in your view you have

<input type='text' name='data' value='George' />
<input type='text' name='data' value='John' />
<input type='text' name='data' value='Paul' />
<input type='text' name='data' value='Ringo' />

Then in your controller you can use

public ActionResult Create(string[] data)
    //data should now be a string array of 4 elements
    return RedirectToAction("Index");