WebServices中ArrayList做參數為什么有問題
發表于:2007-06-30來源:作者:點擊數:
標簽:
我在WebService中寫了一個方法,用ArrayList做參數,返回也是ArrayLsit [WebMethod] public ArrayList GetArrayList2(ArrayList arrayList) { return arrayList; } 然后我在一個ASP.NET的客戶端調用 private void Button1_Click(object sender, System.EventA
我在WebService中寫了一個方法,用ArrayList做參數,返回也是ArrayLsit
[WebMethod]
public ArrayList GetArrayList2(ArrayList arrayList)
{
return arrayList;
}
然后我在一個ASP.NET的客戶端調用
private void Button1_Click(object sender, System.EventArgs e)
{
localhost.Service1 s = new TestWeb.localhost.Service1();
ArrayList al = new ArrayList();
al.Add("arrayList_1");
al.Add("arrayList_2");
//下面這句要出錯,說al不能轉變成object[]類型
ArrayList aa = s.GetArrayList2(al);
foreach(string str in aa)
{
Response.Write(str);
}
}
查看vs
.net自動生成的Reference.cs文件,發現參數實際變了
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetArrayList2", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public object[] GetArrayList2(object[] arrayList) {
object[] results = this.Invoke("GetArrayList2", new object[] {
arrayList});
return ((object[])(results[0]));
}
這是為什么啦?
原文轉自:http://www.kjueaiud.com