How do I call web services in C# that have class objects as parameters?

101 Views Asked by At

There are no run-time errors. But I can't invoke these web services. The invoke button works perfectly fine for web methods with no class object as a parameter. Here is my code.

public class WebService : System.Web.Services.WebService
    {
        [Serializable]
        public class Animal { 
            public int Age { get; set; }
            public string Name { get; set; }

            public string Sound(string name)
            {
                return $"{name} shouting";
            }
        }
        
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string getAnimal(Animal animal)
        {
            Animal animal1 = new Animal();
            string response = string.Empty;
            animal.Age = 5;
            animal.Name = "Keesha";
            response = animal1.Sound(animal1.Name);
            return response;
        }
}`

When I run the program, it says that "The test form is only available for methods with primitive types as parameters." I added the image to get a clearer understanding. I need to test this application on my machine, but I cannot debug the code because the invoke button is not appearing. I am kindly looking for your help.`

This is the image. The invoke button does not appear. [1]: https://i.stack.imgur.com/TsQgD.png

0

There are 0 best solutions below