WebServices and Functions accepting Generic Lists

Hey Everyone, hopefully someone can help me with a little problem I have.

I've coded a webservice to update a database on a server and I call it via a small application I've created anyways the webservice contains a function that takes in a datatable containing the actually database data (which seems to pass alright) and a couple of generic lists used to create the table if it doesn't exist. Problem I have is I've declared my functions in the webservice like the following

<WebMethod()>_
Public Function ServerDataDB(ByVal Job as String, ByVal ColumnNames As Generic.List(Of String), ByVal TableData As DataTable) As boolean

Now when I add a reference to it in my application it tells me that ColumnNames needs to be passed as type string instead of Generic.List and will not allow me to push my genericlists through to it. Does this have to do something with generic.lists are you simpl ynot allowed to push them into a function or is it because its being run as a webserivce Also if those are the causes is there anyways to get around it or am going to have to recode with arrays instead.

Thanks for any help in advance.



Answer this question

WebServices and Functions accepting Generic Lists

  • Husk60

    Hi Mitch,

    I tried this out and you are right - it asks that ColumnNames be passed as a String Array (not String).

    So the signature on the client side looks like - ServerDataDB(ByVal Job as String, ByVal ColumnNames As String(), ByVal TableData As DataTable)
    And you can call it like - Service.ServerDataDB(Job, ColumNamesList.ToArray, TableData) - assuming you already have the lists coded up.
    You could also call like - Service.ServerDataDB(Job, New String(){"Column1", "Column2"}, TableData)

    As for the reason for this berhavior - I am not entirely sure why the type representation does not match exactly. It could be that this is an example of all the magic that happens as a result of XmlSeralization

    Hope this helps,
    Shyam



  • Leon Mayne

    Hmm, well here's a little follow up for anyone thats interested, I haven't tried the array method yet posted above but I believe it would work. The only reason I can figure out as to why this problem occurs is because of a generic.list being Qoute, UnQoute a dynamic item and the XML Serialization of a dynamic object simply does not work. I guess... I don't fully understand why but thats the best explination I can come up with, I know it has to do with a XML Serialization of the Generic.List and my educated guess was that due to it being as I said a dynamic object it simply can't be serialized.

    Would be awsome if anyone else could verify for me that this was the problem, and my diagnosis of the problem is correct.


  • WebServices and Functions accepting Generic Lists