2

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?

marc_s
759k185 gold badges1.4k silver badges1.5k bronze badges
asked Oct 20, 2012 at 19:05
4
  • Can you include the complete error message? Commented Oct 20, 2012 at 19:16
  • 1
    Refresh web service reference. Commented Oct 20, 2012 at 19:21
  • Your error clearly says you should pass SoapWebServiceClient.WebServiceSample.ArrayOfString not string[] Commented Oct 20, 2012 at 19:54
  • Thanks for reply, how do i do that? how do connect SoapWebServiceClient.WebServiceSample.ArrayOfString to the array i defined parameterNames? Commented Oct 20, 2012 at 20:02

2 Answers 2

3

Try this

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

or

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

Check these links

Hope that helps!

answered Oct 21, 2012 at 6:31

Comments

0

A simple way is:

In JavaScript build a new array:

var myArray = new Array();
myArray.push([value1, value2,...]);

In C# just create an ICollection parameter to get your matrix:

[WebMethod(EnableSession = true)]
public MyMethod[] GetMatrixFromJavascript(System.Collections.ICollection myArray)
{ 
 ... 
}
Patrick
6,00416 gold badges68 silver badges108 bronze badges
answered Jul 28, 2017 at 14:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.