WCF - Entity Structure - ERR_CONNECTION_RESET

I am having a problem with my WCF service. Here

    [OperationContract]
    [WebGet(UriTemplate = "/needs", ResponseFormat = WebMessageFormat.Json)]
    List<CustomerNeed> getAllCustomerNeeds();

When I go to the page calling this service, I got this error

GET http://localhost:666/rest/Service1.svc/needs net::ERR_CONNECTION_RESET

When I try to return a string instead of List, it works.

CustomerNeed is a class generated from my database through EntityFramework.

In my service, I call another method, which is in another class;

    public List<CustomerNeed> getAllCustomerNeeds()
    {
        var needs = from cn in db.CustomerNeeds
                    select cn;

        List<CustomerNeed> list = new List<CustomerNeed>();

        foreach (CustomerNeed cusN in needs)
        {
            list.Add(cusN);
        }
        return list;
    }

Maybe this is because I have a foreign key in my CustomerNeed table?

When I do LINQ to entity to import my database, do I need to import tables created due to many, many relationships?

+1
source share
2 answers

, CustomerNeeds, . , WCF.

: 1) CustomerNeeds DataContract. :

[DataContract]
public class CustomerNeeds 
{
   [DataMember]
   public SomeDataType PropertyName {get; set;}
}

2) , getAllCustomerNeeds() CustomerNeed clien

.

+1

, / db, , framework, . , ( , , .)

, , , - :

public List<CustomerNeed> getAllCustomerNeeds()
{
    using (var db = new YourContext()) // plug in your context object
    {
        return db.CustomerNeeds.ToList();
    }
}

, , " ", - , " "? WCF, , , .

, !

0

All Articles