我写了个webservice里面有两个WebMethod:
[WebMethod]
public ArrayList cs()
{
ArrayList resu = new ArrayList();
resu.Add("1");
resu.Add("2");
return resu;
}
/*
测试
*/
[WebMethod]
public string cs1(ArrayList c)
{
string bb;
bb = c[0].ToString();
return bb;
}
我的客户端是BCB,调用第一个WebMethod:cs很正常,调用第2个WebMethod:cs1的时候,总是报:
System.Web.Services.Protocols.SoapException:服务器无法处理请求。--->System.NullReferenceException :未将对象引用设置到对象的实例。
是在这行出的错:bb = c[0].ToString();
没有实例,难道ArrayList没有传入吗?请有知道的兄弟帮我看看,万分感谢
[WebMethod]
public ArrayList cs()
{
ArrayList resu = new ArrayList();
resu.Add("1");
resu.Add("2");
return resu;
}
/*
测试
*/
[WebMethod]
public string cs1(ArrayList c)
{
string bb;
bb = c[0].ToString();
return bb;
}
我的客户端是BCB,调用第一个WebMethod:cs很正常,调用第2个WebMethod:cs1的时候,总是报:
System.Web.Services.Protocols.SoapException:服务器无法处理请求。--->System.NullReferenceException :未将对象引用设置到对象的实例。
是在这行出的错:bb = c[0].ToString();
没有实例,难道ArrayList没有传入吗?请有知道的兄弟帮我看看,万分感谢
public string cs1(ArrayList c)
{
string bb="";
if(c!=null && c.Length>=1)
{
bb = c[0].ToString();
}
return bb;
}
这样是不错了,因为bb=c[0].ToString()不执行了,c是NULL,怎么回事啊
using System.Collections.Generic;
using System.Text;
using System.Collections;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program pr = new Program();
Console.WriteLine( pr.cs1(pr.cs()));
}
public ArrayList cs()
{
ArrayList resu = new ArrayList();
resu.Add("1");
resu.Add("2");
return resu;
}
public string cs1(ArrayList c)
{
string bb;
bb = c[0].ToString();
return bb;
}
}
}
[WebMethod]
public ArrayList cs()
{
ArrayList resu = new ArrayList();
resu.Add("1");
resu.Add("2");
return resu;
}
/*
测试
*/
[WebMethod]
public string cs1(ArrayList c)
{
c=cs(); string bb;
bb = c[0].ToString();
return bb;
}
你调一下