2013-03-17 67 views
0

我有一個ASMX webservice,並有一個方法返回一個ArrayList ..它工作正常,但我不知道如何從客戶端代碼獲取數組項目。這裏是ASMX方法如何從asmx webmethod返回ArrayList

[WebMethod] 
public ReturnParcel[] getConStrings(string dbType) 
{ 
    var OdbName = GetSetting(document, "Odbname"); 
    var OuserName = GetSetting(document, "Ousername"); 
    var Opassword = GetSetting(document, "Opassword"); 
    if (dbType == "Oracle") 
    { 
     return new ReturnParcel[] {new ReturnParcel { DBName = OdbName, UserID = OuserName, Password = Opassword },}; 
    } 
    else 
    { 
     return new ReturnParcel[] {new ReturnParcel { DBName = SdbName, UserID = SuserName, Password = Spassword },}; 
    } 
} 

public class ReturnParcel 
{ 
    public string DBName { get; set; } 
    public string UserID { get; set; } 
    public string Password { get; set; } 
} 

客戶端代碼:

WebServiceProxy.OraSPDataXchange objServiceClient = new WebServiceProxy.OraSPDataXchange(); 
objServiceClient.Url = "http://portal.mydomain.local/_layouts/SPCustomWS/OraSPDataXchange.asmx"; 

objServiceClient.getConStrings("Oracle"); 

檢查客戶端code..there的最後一行我需要得到一個返回values..so需要知道如何得到它這裏..

+0

您的方法似乎要返回Array of ReturnParcel項目,而不是ArrayList。在客戶端部分,您已經獲得了這些值,但只是忽略了返回值。你究竟想達到什麼目的?爲什麼不這樣做:ReturnParcel [] items = objServiceClient.getConStrings(「Oracle」); ? – 2013-03-17 15:26:43

+0

您是否試圖將返回的項目轉換爲'ArrayList'? – Brian 2013-03-17 15:27:53

+2

客戶端代理中的集合類型不需要與服務器端集合類型的類型相同。該類型在代理生成器中配置。 – 2013-03-17 15:28:48

回答

2

我認爲

var receivedConnectionStrings = objServiceClient.getConStrings("Oracle"); 

會把結果在receivedConnectionStrings變量。

+0

Albin你說得對:)你認爲這會給我的價值嗎? string adbname = receivedConnectionStrings [0] .DBName.ToString(); string auserid = receivedConnectionStrings [1] .Password.ToString(); – user342944 2013-03-17 16:48:11