0 Replies - 2586 Views - Last Post: 14 April 2014 - 10:55 AM

#1 chief2787  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 24-March 12

return an array from a .net web service to a console application

Posted 14 April 2014 - 10:55 AM

I'm try to write a simple web service than returns a Fibonacci number series (the next number in the series is the sum of the previous two eg. 0,1,1,2,3,5,8,13,21,34 etc.). The length of the series returned is set by the users input. At the moment I'm getting the error "No overload for method 'Fibonacci' takes 2 arguments" in the console app
Console.Write(webservice.Fibonacci(j,Fseries));
. I thought I am passing it two arguments? Any help with this would be much appreciated.

Here is the code for the console app

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fibonacci_series_calculator.testweb;

namespace Fibonacci_series_calculator
{

    class Program
    {
        static void Main(string[] args)
        {

            Service1 webservice = new Service1();
            Console.WriteLine("Please enter the amount of fibonacci numbers required:");
            string input = Console.ReadLine();
            int j = Convert.ToInt32(input);
            int[] Fseries = new int[j]; 

            Console.Write(webservice.Fibonacci(j,Fseries));
            
            //Console.WriteLine("The Fibonacci numbers are:");
             
        }
    }
}




Here is the web service code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;


namespace Fibonacci_web_service
{
   
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]

  
    public class Service1 : System.Web.Services.WebService
    {
       
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public int[] Fibonacci(int n,int[] FibArr)
        {
            
            
            int j = 0;
            int k = 1;
            int temp;

            for (int i = 0; i < n; i++)
            {
                temp = j;
                j = k;
                k = temp + k;
                FibArr[i] = j;
            }
            
            return FibArr;
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1