Search code examples
c#wcflistgenericsoperation-contract

WCF type conversion


I am stuck with this error..can anyone point me in right direction In my WCF service ..I have a operationcontract defined as follows...

  [OperationContract]
  [FaultContract(typeof(ProductFault))]
  BusinessResponse<List<Product>> GetProductList(int id);

I am calling the above method from a console application as follows..

LookUpServiceClient client = new LookUpServiceClient();

BusinessResponse<List<Product>> response = client.GetProductList(2); 

But the lines client.GetProductList(2); is underlined with Red in VS2012. If I move my mouse over it ..I get error displayed as ..

enter image description here


Solution

  • By default, WCF proxy generation creates arrays for all collection types. So, you can fix this problem by changing your variable assignment to this

    BusinessResponse<Product[]> reponse = client.GetProductList(2);
    

    You can also change the default collection type generated by the proxy by choosing a collection type in the Advanced Settings (Array, List, ArrayList, etc.)