首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

调用C# webservices时,返回datatable在其它电脑下出错

2013-01-11 
调用C# webservices时,返回datatable在其它电脑上出错在我的电脑上运行没问题:在其它电脑上提示:无法将类

调用C# webservices时,返回datatable在其它电脑上出错
在我的电脑上运行没问题:在其它电脑上提示:无法将类型为“EnterpriseServerBase.WebService.DynamicWebCalling.userloginResponseUserloginResult”的对象强制转换为类型“System.Data.DataTable
1,webservices:方法
  [WebMethod(Description = "验证方法")]   
    public DataTable userlogin(string username, string userpwd, string macip, string notesis)
    {
        try
        {
            DataTable DT = Database.userlogin(username,userpwd,macip,notesis);
            if (DT != null)
            {
                return DT;
            }
            else
            {
                return null;
            }

        }

        catch (Exception)
        {
            return null;
        }
    }
2,调用引用http://developer.51cto.com/art/200908/144594.htm
C#动态调用Web服务方法二:完全动态处理,传入服务服务网址,方法名和参数即可.    public static object InvokeWebService(string url, string classname, string methodname, object[] args)   
        {   这个函数
3,调用如下
   userinfo.Adminrole2 = @"http://*.*.*.*:8805";
           //   userinfo.Adminrole2 = @"http://60.222.247.4:8206";
            string url = userinfo.Adminrole2+@"/gpwebservice/hjgplogin.asmx";
            string[] args = new string[4];
            args[0] = this.Tusername.Text;
            args[1] = Md5power.MD5Encrypt(this.Tuserpwd.Text);
            args[2] = getIpaddress() + GetMacAddressByNetworkInformation();
            args[3] = "1";
            DataTable result =(DataTable) WebServiceHelper.InvokeWebService(url, "userlogin", args);   //验证
           // this.Tusername.Text = result.ToString();
            if (result!= null)
            {
在其它电脑上提示红色字体出错,转datatable有问题,可在我的电脑上转换没问题,求解决方法,谢谢
------解决方案--------------------


DataTable result =(DataTable) WebServiceHelper.InvokeWebService(url, "userlogin", args); 
这个方法是不是少写了一个参数,如果不是把你的这个方法WebServiceHelper.InvokeWebService贴上去看看
[解决办法]
public static object InvokeWebService(string url, string classname, string methodname, object[] args)  
这个方法是4个参数,而你调用只用了3个参数

热点排行