Passing string array to webservice method

21,688

Try this

SoapWebServiceClient.WebServiceSample.ArrayOfString arrString = SoapWebServiceClient.WebServiceSample.ArrayOfString();

arrString.AddRange(parameterNames);

or

arrString.Add(....); //if that exists

Check these links

Hope that helps!

Share:
21,688

Related videos on Youtube

user1754598
Author by

user1754598

Updated on July 29, 2020

Comments

  • user1754598
    user1754598 almost 4 years

    I have a web service with this method:

    [WebMethod]
    public int[] stringTest(string[] tString)
    {
    
        int numberOfStrings = tString.Length;
        int[] returnS = new int[numberOfStrings];
        for (int i = 0; i <= numberOfStrings; i++)
        { 
            returnS[i] = 1;
    
        }
        return returnS;
    }
    

    And then I'm trying to pass an array of strings to it from a client program as following:

    var client = new WebServiceSample.WebService1SoapClient();
    string[] parameterNames = { "Windsensor","Temperature sensor"};
    test = client.stringTest(parameterNames);
    

    But I'm getting these errors:

    The best overloaded method match for 'SoapWebServiceClient.WebServiceSample.WebService1SoapClient.stringTest(SoapWebServiceClient.WebServiceSample.ArrayOfString)' has some invalid arguments

    and

    Argument 1: cannot convert from 'string[]' to 'SoapWebServiceClient.WebServiceSample.ArrayOfString'

    What is wrong with my code?