0

I have tried a lot of solutions from the internet. But I am not able to resolve this problem.

I have tried solutions from these links below:

WCF Proxy Returning Array instead of List EVEN THOUGH Collection Type == Generic.List

WCF Returning Array instead of List EVEN THOUGH Collection Type == Generic.List

Why does WCF return myObject[] instead of List<T> like I was expecting?

But I am not able to resolve it.

I have 2 copies of the same wcf service source code "WCFServiceApplication". One is hosted on LAN on IIS7 and Other one is am running locally in my solution.

The one which is hosted on IIS7 is working fine and returning list of objects. But the one on my local solution. I am trying to reference locally in solution to consume "WCFServiceApplication" functions in one of my local project named "MyProjectLibrary.csproj".

But here i have the problem. It is not giving me the Generic List of my custom class objects.

Any help is appreciated.

Thanks

I am Returning the List of below class:

[DataContract(IsReference = true)]
[KnownType(typeof(Joc))]
[KnownType(typeof(Stakeholder))]
[XmlInclude(typeof(JocStakeholder))]
public class JocStakeholder
{
    [DataMember]
    public long ID { get; set; }

    [DataMember]
    public virtual Joc joc { get; set; }

    [DataMember]
    public virtual Stakeholder stakeholder { get; set; }

}

Joc and Stakeholder are 2 other classes. Actually, these are code first entities.

And My interface has this function:

[ServiceContract]
public  interface IService
{
    [OperationContract]
    public IList<JocStakeholder> GetJocStakeHolders();
}
Community
  • 1
  • 1
Aman Thakur
  • 159
  • 4
  • 14

3 Answers3

1

Change the Client's Service Reference Settings as follows

Right Click the Service Reference and Choose Configure Service Reference

Under the Data Type property settings, change the Collection Type value from Array to

System.Collections.Generic.List

This would give you the Generic List as a response

Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
Karthik
  • 1,064
  • 2
  • 16
  • 33
0

Specifies the list collection type for a WCF client. The default type is Array.

You can change it before adding service reference click Advance in Add Service Reference Dialog Box. Under Data Type beside Collection Type select in drownlist System.Collections.Generic.List.

jtabuloc
  • 2,479
  • 2
  • 17
  • 33
0

I tried mostly all the method which i saw on the Stackoverflow.com and Internet. But i couldn't find one that could have done the job for me.

SO, finally, I found this article WCF the Right Wat by Miguel Castro and I implemented by services with the same architecture as the Miguel Sir is doing. The architecture resolved the problem.

But some programmers might not agree with the Architecture which is being used in that article because Model Classes project is being distributed to the clients as a DLL. Whereas in WCF usually, the Classes are exposed through the Service.

Aman Thakur
  • 159
  • 4
  • 14