friends i am trying to pass an array to asp webservice method from my console application the error is that "The best overloaded method has some invalid arguments "
Below is console side in which function i am passing array is giving error.
int[] t = new int[6];
ServiceReference1.WebService1SoapClient client=new ServiceReference1.WebService1SoapClient();
for (int i = 0; i < 7; i++)
{
t[i] = Convert.ToInt32(Console.ReadLine());
}
client.bublesort(t); //Here is the error in passing to webservice method
On other hand my WEBSERVICE method code is that int temp = 0;
[WebMethod]
public int[] bublesort(int[] arr)
{
for (int i = 0; i < 5; i++)
{
for (int j = i + 1; j < 6; j++)
{
if (arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
-
1What is the error you are getting?Darek– Darek2014年12月26日 04:21:37 +00:00Commented Dec 26, 2014 at 4:21
-
cannot pass the array into the method.method is in webservice...the error is that.. "The best overloaded method has some invalid arguments "user4182613– user41826132014年12月26日 04:25:31 +00:00Commented Dec 26, 2014 at 4:25
-
What is the method's signature on the client side?Darek– Darek2014年12月26日 04:34:50 +00:00Commented Dec 26, 2014 at 4:34
1 Answer 1
You problem is that you have created ASMX web service and tried to add as Service Reference.
If you check method signature in your client it is not accepting Array of integer. Instead of this it has ServiceReference1.ArrayOfInt class object.
ServiceReference1.WebService1SoapClient client=new ServiceReference1.WebService1SoapClient();
for (int i = 0; i < 7; i++)
{
t[i] = Convert.ToInt32(Console.ReadLine());
}
ServiceReference1.ArrayOfInt item = new ServiceReference1.ArrayOfInt();
item.AddRange(t);
ServiceReference1.ArrayOfInt result = client.bublesort(item);
foreach (var i in result)
{
Console.WriteLine(i);
}
I think this will solve your problem.