WebServices中ArrayList做參數為什么有問題
2024-07-21 02:21:23
供稿:網友
我在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]));
}
這是為什么啦?