Sahil Sharma
Sahil Sharma

Reputation: 37

Not able to consume WCF services in MVC

I am getting a strange error.The code was working fine few days back. But now its throwing error. I tried to googling to find out the solution but not able to find it. I am creating an entities using code first in entity framework. Now,while adding a new entities using code first in entity framework and consuming the methods using WCF service in MVC, its start throwing error in UI part (MVC) like

Error: Cannot implicitly convert type 'Campus.Web.ViewModel.CampusWebService.ExpenseAccount[]' to 'System.Collections.Generic.List'

Newly created class in EF

[DataContract(IsReference = true)]
[KnownType(typeof(AccountCategoryMajor))]
[KnownType(typeof(ActivityReport))]

[XmlInclude(typeof(AccountCategory))]
public class AccountCategory : BaseEntity
{

    [DataMember]
    public long AccountcategoryMinnorID { get; set; }

    [DataMember]
    public virtual List<AccountCategoryMinnor> AccountCategoryMinnors { get; set; }

    [DataMember]
    public long ExpenseID { get; set; }

    [DataMember]
    public virtual Expense expense { get; set; }

}

when i deleted my newly created class entities its start working fine. I don't know y it is happening.
I am able to run Wcf services alone even and even i am getting entities relationship in the backend. Thanks in Advance.

Upvotes: 0

Views: 86

Answers (2)

Pastew
Pastew

Reputation: 21

I had the same issues. Cleaning the solution, rebuilding and restarting Visual Studio always worked (really).

You could also try to use Array instead of List in your DataContract and convert it to List on the client side.

Upvotes: 0

Khatibzadeh
Khatibzadeh

Reputation: 470

While adding Service Reference in Advanced button change the Collection type to System.Collections.Generic.List would resolve the issue

Upvotes: 1

Related Questions