Note that there are some explanatory texts on larger screens.

plurals
  1. POASMX Web Service - Return user defined class with properties
    primarykey
    data
    text
    <p>Hey, I am trying to return a user defined class from a web method. The class has properties and/or methods. Given the following web method: </p> <pre><code>[WebMethod] public List&lt;MenuItem&gt; GetMenu() { List&lt;MenuItem&gt; menuItemList = new List&lt;MenuItem&gt;(); menuItemList.Add(new MenuItem()); menuItemList.Add(new MenuItem()); menuItemList.Add(new MenuItem()); return menuItemList; } </code></pre> <p>Now, suppose this web service is consumed by adding a web reference in a newly created console application. The following code is used to test it: </p> <pre><code>public void TestGetMenu() { MenuService service = new MenuService.MenuService(); service.MenuItem[] menuItemList = service.GetMenu(); for (int i = 0; i &lt; menuItemList.Length; i++) { Console.WriteLine(menuItemList[i].name); } Console.ReadKey(); } </code></pre> <p>First of all, this doesn't work if the MenuItem class contains properties... Also, if the MenuItem class contains a method the call to the web method doesn't fail, but the method is not in the generated proxy class.. for example: menuItemList[i].getName() does not exist. Why? What am i missing?</p> <pre><code>//This works public class MenuItem { public string name; public MenuItem() { name = "pizza"; } } //This crashes / doesnt work public class MenuItem { private string name; public MenuItem() { name = "pizza"; } public string Name { get { return name; } set { name = value; } } } //This successfully calls web method, but the method does not exist during test public class MenuItem { private string name; public MenuItem() { name = "pizza"; } public string getName() { return name; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload