我写了个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没有传入吗?请有知道的兄弟帮我看看,万分感谢

解决方案 »

  1.   

    if (c.Length > 0 && c[0] != null) bb = c[0].ToString(); 
      

  2.   

    if (c != null && c.Length > 0 && c[0] != null) bb = c[0].ToString(); 
      

  3.   

    这程序是没问题的,错误只在你传的参数ArrayList c没有值,你不应该在这段程序里找问题
      

  4.   


     public string cs1(ArrayList c) 
            { 
                string bb="";
                if(c!=null && c.Length>=1)
                    { 
                         bb = c[0].ToString(); 
                    }
               return bb; 
             } 
      

  5.   


    这样是不错了,因为bb=c[0].ToString()不执行了,c是NULL,怎么回事啊
      

  6.   

    using System;
    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;
            } 
        }
    }
      

  7.   

    了个webservice里面有两个WebMethod: 
            [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; 
            } 
      

  8.   

    顶一下.....对..你add那里咋回事?????
    你调一下
      

  9.   

    客户端的参数没问题,但是传到WEBSERVICE就是空的了.不知道怎么回事情.现在改了WEBSERVICE的CS1方法,把传入的ARRAYLIST参数类型改成数组,就可以了,但是为什么ARRAYLIST不行,留以后再说吧,先把手上的程序应付过去再说.再次感谢大家.结贴