简体   繁体   中英

C# pass List<List<int>> to a Web Service

The thread is exactly what I need,

I have this:

WebService :

....
List<List<Int64>> whau = new List<List<Int64>>();
....
[WebMethod]
static setList(List<List<Int64>> list_web)
{
    whau = list_web;
}

C#

public void func1 ()
{
    List<List<Int64>> list = new List<List<Int64>>();
    List<Int64> sublist = new List<Int64>();
    sublist.Add(1);
    sublist.Add(2);
    list.Add(sublist);

    service.setList(????);
}

But nothing works, I mean I've tried to send a List to the WebService , I used

sublist.ToArray() 

and that works, but how to send the

List<List<>> var ?

Need really help !!

Edit :

I've already tried to do this :

service.setList(list);

and that works if the WebMethod is near the func1() , but of course the goal of WebService is not to be implemented in the same place that the Business Software...

Change your List<List<T>> to T[,] and see if it works.

Your code will look like

....
Int64[,] whau = new Int64[X,Y]; // I don't know the size of this.
....
[WebMethod]
static setList(Int64[,] list_web)
{
    whau = list_web;
}

public void func1 ()
{
    Int64[,] list = Int64[1, 2];
    list[0, 1] = 1;
    list[0, 2] = 2;
    service.setList(list);
}

Remember that this is only an example. I don't know your actual code. This may cause compilation errors, but I think they will be easy to solve out.

Ok budies, so what I ve done is simple finally, I just send a list to the webservice, and the webservice recieve that list and insert it to another list, so is the WebService who creates the Nested List.

Thank you very much about your help you all !!

Regards !

FB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM