簡體   English   中英

C#通過列表 <List<int> &gt;到Web服務

[英]C# pass List<List<int>> to a Web Service

線程正是我所需要的,

我有這個:

Web服務

....
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(????);
}

但是沒有任何效果,我的意思是我嘗試將List發送到WebService

sublist.ToArray() 

並且有效,但是如何發送

List<List<>> var ?

需要真正的幫助!

編輯

我已經嘗試這樣做:

service.setList(list);

如果WebMethodfunc1()附近,那將起作用,但是當然, WebService的目標不能在與商業軟件相同的地方實現。

將您的List<List<T>>更改為T[,] ,看看是否可行。

您的代碼看起來像

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

請記住,這僅是示例。 我不知道您的實際代碼。 這可能會導致編譯錯誤,但是我認為它們很容易解決。

好的,伙計們,所以最后要做的事情很簡單,我只是將一個列表發送到Web服務,然后Web服務接收該列表並將其插入到另一個列表中,創建嵌套列表的WebService也是這樣。

非常感謝您對大家的幫助!

問候 !

FB

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM