vb.net - How to return two objects (including one list) in JSON with WCF -
i trying resolve issue.
this service contract (iservice1.vb)
<operationcontract()> _ <webinvoke(method:="get", bodystyle:=webmessagebodystyle.wrapped, responseformat:=webmessageformat.json, uritemplate:="/getbooks")> _ function getbooks() list(of book) <datacontract()> _ class book public property bookchapter() list(of chapter) return m_bookchapter end set(value list(of chapter)) m_bookchapter = value end set end property private m_bookchapter list(of chapter) public property success() integer return m_success end set(value integer) m_success = value end set end property private m_success integer end class <datacontract()> _ class chapter public property description() string return m_description end set(value string) m_description = value end set end property private m_description string end class
this service (service1.vb)
public function getbooks() list(of igpservice.book) implements igpservice.getbooks dim books new list(of igpservice.book) dim newbook igpservice.book = new igpservice.book integer = 0 3 dim newchapter igpservice.chapter = new igpservice.chapter newchapter.description = "chapter1" newbook.bookchapter.add(newchapter) next newbook.success = 1 books.add(newbook) return books end function
when call getbooks, following error:
the server encountered error processing request. see server logs more details.
i don't know wrong here. couldn't find in windows eventlog.
i added new() contructor book class , works. don't know why!
class book public property bookchapter() list(of chapter) return m_bookchapter end set(value list(of chapter)) m_bookchapter = value end set end property private m_bookchapter list(of chapter) public property success() integer return m_success end set(value integer) m_success = value end set end property private m_success integer **public sub new() bookchapter = new list(of chapter) end sub** end class
i want understand why is. can explain me difference , without new()!
Comments
Post a Comment