forum

Home / DeveloperSection / Forums / Is it possible to iterate a loop in an Asp.Net web service

Is it possible to iterate a loop in an Asp.Net web service

Anonymous User 2025 11-Dec-2014

I have a console application in which I am using an asp.net webservice.Also,I had declared a display method in my service which accepts and iterates a string array.But,when I executed the console application it showed an empty console window.Why the array contents are not being displayed? 

Code that uses the below service 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
namespace usingWebServiceExample
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arr = new string[3] {"harry","ronn","sheldon" };
            localhost.Service service = new localhost.Service();
            service.display(arr);
            Console.Read();
        }
    }
}

Service Code: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 Service : System.Web.Services.WebService
{
    public Service()
    {
    }
 
    [WebMethod]
    public void display(string[] arr)
    {
        for (int i = 0; i < arr.Length; i++)
        {
            Console.WriteLine(arr[i]);
        }
    }
}


Updated on 11-Dec-2014
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By