日期:2014-05-17  浏览次数:20830 次

调用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有问题,可在我的电脑上转换没问题,求解决方法,谢谢