asp.net - my web servie returns a list<myStruct> but the values dissapear? -
i have web service function returns list 6 entries, uses custom struct. reference updates on client side project, list returned, while having correct number of entries, has data fields not listed , replaced 1 called "propertychanged" null.
my guess i'm missing serialize properly, here's code:
struct:
public struct treedata { private readonly string text; private readonly string parent; private string val; public treedata(string text, string parent) { this.text = text; this.parent = parent; this.val = ""; } public treedata(string text, string parent, string value) { this.text = text; this.parent = parent; this.val = value; } [xmltext()] public string text { { return text; } } [xmltext()] public string parent { { return parent; } } [xmltext()] public string value { { return val; } } }
the web method (simplified):
[system.xml.serialization.xmlinclude(typeof(treedata))] [webmethod] public list<treedata> getlist() { list<treedata> mylist = new list<treedata>(); mylist.add(new treedata("one", "two")); return mylist; }
client-side function:
protected void page_load(object sender, eventargs e) { username = session["username"].tostring(); using (servicereference1.service1soapclient myservice = new servicereference1.service1soapclient()) { demogs = userinfo[0]; agencies = userinfo[1]; list<treedata> treenodes = myservice.loadsites( demogs, agencies, true).tolist(); datatable table = myservice.gettable(); mygrid.datasource = table; mygrid.databind(); } }
so right before webmethod returns, list looks correct:
mylist count = 3 [0] parent= "one" text = "two" value = "three" [1] parent= "1" text = "2" value = "3" [2] parent= "a" text = "b" value = "c"
after returning , assigning treenodes looks like:
treenodes count = 3 [0] propertychanged = null; [1] propertychanged = null; [2] propertychanged = null;
i think might confusing serialization attributes. if you're using wcf webservices might need use datacontract
, datamember
attributes specify members of struct should included.
Comments
Post a Comment