-1

I have a WCF service with many functions. Some of them contain List<string> arguments. e.g

[ServiceContract]
public interface IQueriesService
{

    [OperationContract]
    DataTable ExecuteSimpleQuery(List<string> sel, List<string> fr, List<string> whereCells, List<string> types, List<string> whereOps, List<string> whereValues, List<string> logOp, int cultureLCID);
}

public class UniverService : IQueriesService
{

    public DataTable ExecuteSimpleQuery(List<string> sel, List<string> fr, List<string> whereCells, List<string> types, List<string> whereOps, List<string> whereValues, List<string> logOp, int cultureLCID)
    {

        DataTable dt = new DataTable();
        ...
        return dt;
    }
}

simpleQ.Select = simpleQ.Select.Distinct().ToList();
simpleQ.From = simpleQ.From.Distinct().ToList();
DataTable dt = svc.ExecuteSimpleQuery(simpleQ.Select, simpleQ.From, simpleQ.WhereCell, simpleQ.Type, simpleQ.WhereOp, simpleQ.WhereValue, simpleQ.LogicOperation, Thread.CurrentThread.CurrentUICulture.LCID);

where simpleQ.Select, From, ... are of type List<string>

When I add my service reference to other project, in Service Reference Settings window I change Collection Type from System.Array to System.Collections.Generic.List. My problem is that the mentioned conversion works for some of my functions and doesn't for others. I mean after adding service reference and rebuilding it I get an error Cannot convert from List to string[] . When I look into generated proxy classes, I see that those functions really have string arrays (and not lists) as their arguments. Who can help me?

Tim
  • 28,212
  • 8
  • 63
  • 76
  • I would take a guess that the ones that are working have a return type of `List` where as the one that you have displayed in your question has a return type of `DataTable` are you familiar with return types when using methods..? also stepping thru the code would probably yield the answer in regards to where your code functionality / logic is breaking down – MethodMan Dec 01 '14 at 16:51
  • interesting consideration, but i looked at my codes and 1. `void DeleteStudents(List ids);` this one works 2. `void SaveXMLQuery(string title, string description, bool isFavourite, List fr, List sel)` also not working... is there anything i should know about return types? may be i would understand after it... – Artak Khachatryan Dec 01 '14 at 16:56
  • `Artak` post all code updates in your original question also show the code with full method signature.. you need to show that as well as how the method is being called also show how you declared or assigned `fr` and `sel` show all relevant code – MethodMan Dec 01 '14 at 16:58
  • please see the updated version – Artak Khachatryan Dec 01 '14 at 17:14
  • may this will be useful to know that those functions which are not working have auto generated Request/Response classes in service reference, but the working ones doesn't(they are implemented with full list of arguments) – Artak Khachatryan Dec 01 '14 at 19:26
  • ??? what are you trying to say.. can you be more specific as well as edit your comment to make more readable sense please – MethodMan Dec 01 '14 at 19:27
  • @DJKRAZE i found the issue. If comment all the functions in my interface which have `DataTable` as their return type, the proxy classes are fully generated and i don't get such an error for other functions. But if i uncomment just one of those functions, then the proxy classes are generated with message contracts(although i unchecked the Always generate message contracts check box in Service Reference Settings dialog) – Artak Khachatryan Dec 02 '14 at 06:46
  • it sounds like you are trying to use a single method to return different `DataTypes` you should read up on Method overloading I think that this will help resolve your issue personally – MethodMan Dec 02 '14 at 14:34

1 Answers1

0

you should be able to append the extension method ToList() at the end of the array in question and it should work. If you do not need the features of a list (and instead just need to iterate over the arguments) you could just put the parameter type as IEnumerable<string> instead and both arrays and lists would work as input arguments.

James Ralston
  • 1,170
  • 8
  • 11