测试表单仅适用于将原始类型作为参数的方法

问题描述 投票:1回答:2

我想调试我的web方法,以查看返回列表是否包含已作为参数传递的对象。

我的网络方法如下:

[WebMethod]
       public List<Vehicle> GetCustomerList(Vehicle obj)
            {
                //List<Vehicle> newL = new List<Vehicle> { obj };

                return new List<Vehicle> { obj };

            }

它说:“测试表单仅适用于将原始类型作为参数的方法。”因此,我想知道我需要进行哪些更改才能检查该方法传递的内容。

>后续问题的编辑代码

public class Service1 : System.Web.Services.WebService
    {

   [WebMethod]
             public List<Vehicle> GetCustomerList(Vehicle vehi)
            {
                List<Vehicle> newL = new List<Vehicle> { vehi };
                return new List<Vehicle> { vehi };

            }

            [WebMethod]
            public void simpleCase()
            {
                Vehicle obj = new Vehicle();
                obj.VehicleID = "KL-9876";
                obj.VehicleType = "Nissan";
                obj.VehicleOwner = "Sanjiva";
                GetCustomerList(obj);
            }
    }



    public class Vehicle
    {
        public string VehicleID { get; set; }
        public string VehicleType { get; set; }
        public string VehicleOwner { get; set; }
    }


}
c# asp.net web-services asmx
2个回答
2
投票

声明的方法需要一个Vehicle对象,您不能在表格中键入内容,因此无法输入消息。在一种形式中,您显然只能输入基本类型(int等)


0
投票

要测试非原始参数类型,您需要创建一个使用Web服务的测试应用程序,因此请在与Web Service相同的解决方案中创建一个新应用程序(Windows / Web并不重要)。在同一解决方案中,将Web参考添加到该服务。然后照常使用服务(即创建服务的实例,然后在其上调用方法,并传入任何复杂的参数类型)。

© www.soinside.com 2019 - 2024. All rights reserved.