0

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

publicgk
  • 3,170
  • 1
  • 26
  • 45
bp581
  • 859
  • 1
  • 16
  • 47

2 Answers2

2

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.)

Dylan Meador
  • 2,381
  • 1
  • 19
  • 32
  • Thanks a TON. I spent almost 3 hours trying to explore myself the solution. Thanks again..apprecite the speedy reponse. – bp581 Aug 16 '13 at 19:19
1

As @Dylan Meaodr has pointed out, WCF proxy generation creates arrays for all collection types.

Either way is to change it to array assignment in your client project

OR

you can tell the service to use Generic list by configuring the service.

Details can be found here. Quoting from there -

You can specify that you want to use a generic list instead of an array by clicking the advanced button when you add a reference, or you can right click on the service reference and choose configure to change it in place.

The reason is that WCF serializes Generic lists as arrays to send across the wire. The configuration is just telling svcutil to create a proxy that converts them back to a generic list for your convenience.

If you are adding a Service reference to your project, right click on your service and click on configure which will open configuration window for you where you can change the collection type -

enter image description here

Community
  • 1
  • 1
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185