Hey, I'm trying to return a custom class from a web method. A class has properties and / or methods. Given the following web method:
[WebMethod]
public List<MenuItem> GetMenu()
{
List<MenuItem> menuItemList = new List<MenuItem>();
menuItemList.Add(new MenuItem());
menuItemList.Add(new MenuItem());
menuItemList.Add(new MenuItem());
return menuItemList;
}
Now suppose this web service is consumed by adding a web link to a newly created console application. To check it, use the following code:
public void TestGetMenu()
{
MenuService service = new MenuService.MenuService();
service.MenuItem[] menuItemList = service.GetMenu();
for (int i = 0; i < menuItemList.Length; i++)
{
Console.WriteLine(menuItemList[i].name);
}
Console.ReadKey();
}
First of all, this does not work if the MenuItem class contains properties ... Also, if the MenuItem class contains a method, the web method call is not interrupted, but the method is not in the generated proxy class .. for example: menuItemList [i] .getName ( ) does not exist. What for? What am I missing?
public class MenuItem
{
public string name;
public MenuItem()
{
name = "pizza";
}
}
public class MenuItem
{
private string name;
public MenuItem()
{
name = "pizza";
}
public string Name
{
get { return name; }
set { name = value; }
}
}
public class MenuItem
{
private string name;
public MenuItem()
{
name = "pizza";
}
public string getName()
{
return name;
}
}
Mikey source
share