Method has some invalid arguments?

c#, web-services, winforms

Solution

Web services can't pass complex types like `ArrayList`, or at least not without some configuration, so just simplify your web service. Change it to this:

public int SaveSelectedOffers(object[] offers, int selectedRows)

which is how it's being generated anyway as you can see, and then call it like this:

private void offersAvailableSubmit_Click(object sender, EventArgs e)
{
    object[] options = new object[3];
    options[0] = "item 1";
    options[1] = "item 2";
    options[2] = "item 2";

    int rowsAffected = serviceCaller.SaveSelectedOffers(options, rowCount); 
}

Another option for the initialization of `options`, if you're looking for something more concise, would be like this:

object[] options = new object[] { "item 1", "item 2", "item 3" };

Problem

I am sending data from a windows form to web service in the form of `ArrayList`. In web service declaration of my method is like: ``` [WebMethod] public int SaveSelectedOffers(ArrayList offers, int selectedRows) { } ``` and in windows form, on the button click, my code is: ``` private void offersAvailableSubmit_Click(object sender, EventArgs e) { ArrayList options; options.Add("item 1"); options.Add("item 2"); options.Add("item 2"); //In this line of code it is showing error that Argument 1: cannot convert from 'System.Collections.ArrayList' to 'object[]' int rowsAffected = serviceCaller.SaveSelectedOffers(options, rowCount); } ``` Datatype of options is `ArrayList` and in web service also I am using `ArrayList` type of variable to hold this value, then why this error occur? Is it proper way to send parameter to web service or there is an other way for this?

Original source