0

I am developing a web application using MVC 3 and ASMX Web Services.

I am trying to send a List< object > to a Web Method, but I get the following error:

" cannot convert from 'System.Collections.Generic.List' to 'WebServiceClass.ArrayOfAnyType' "

This is my Web Service definition:

public class WebServiceClass : System.Web.Services.WebService
{
    [WebMethod]
    public bool MyWebMethod(List<object> ParameterValues)
    {
        //do stuff..
    }
}

And this is the block of code where I call the Web Method:

        List<object> ParameterValues = new List<object>();

        WebServiceClass.WebServiceClassSoapClient MyWebService = new WebServiceClass.WebServiceClassSoapClient();

        //I use actual objects here, this is just for an example
        ParameterValues.Add(new DateTime(2012,5,2));
        ParameterValues.Add(23);
        ParameterValues.Add("some string");

        MyWebService.MyWebMethod(ParameterValues);

My idea was to save time and pass Lists of objects to all Web Methods instead of defining WebMethod(DateTime date, int someint, string somestring).

Is there a solution for this?

Best regards.


If your method expects 3 parameters of type DateTime, int, and string than define a method with this arguments. Otherwise you will have to case down and your solution is not type-safe.

Are all your methods in code taking a list of objects as a parameter? Probably not. And the same should apply to web methods.

4

1 回答 1

0

如果您的方法需要 3 个类型的参数,则DateTime使用intstring参数定义一个方法。否则,您将不得不放弃并且您的解决方案不是类型安全的。

您在代码中的所有方法是否都将对象列表作为参数?可能不是。这同样适用于网络方法。

于 2012-08-03T11:10:30.910 回答