0

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;
}
dotnetstep
17.5k6 gold badges61 silver badges80 bronze badges
asked Dec 26, 2014 at 4:15
3
  • 1
    What is the error you are getting? Commented 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 " Commented Dec 26, 2014 at 4:25
  • What is the method's signature on the client side? Commented Dec 26, 2014 at 4:34

1 Answer 1

2

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.

answered Dec 26, 2014 at 5:24

3 Comments

Thanks for solution , but problem is now that it is not giving output when i write as console.writeline(client.bubblesort(item)); to display sorted array it is giving me this in output. "ServiceReference1.ArrayofInt".
Check updated code and also you can also verify that what is return type ?
Oh i am very very very very much thankfull to you dear...you have solved my problem ..... again thanks to you....

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.