XML Serialization Exception

Discussion in 'ASP .Net Web Services' started by Abhishek Srivastava, Mar 1, 2004.

  1. Hello All,

    I am writing a XML WebService. I have two very simpilar methods exposed
    as webService. GetPersonList and GetModuleList.

    The GetPersonList method returns an ArrayList containing PersonVO(id,
    name, fullname) object. And GetModuleList returns and ArrayList
    containing the ModuleVO (id, module name) object.

    The GetPersonList works absolutely fine. But the GetModule List throws
    the following exception

    -------------
    UT.ServiceUT.GetModuleList : System.Web.Services.Protocols.SoapException
    : System.Web.Services.Protocols.SoapException: Server was unable to
    process request. ---> System.InvalidOperationException: There was an
    error generating the XML document. --->
    System.InvalidOperationException: The type CommonComponents.ModuleVO was
    not expected. Use the XmlInclude or SoapInclude attribute to specify
    types that are not known statically.
    at
    System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String
    name, String ns, Object o, Boolean xsiType)
    at
    ------------

    Funny thing is that if I go an add the following method to my asmx.cs
    file (WITH NO OTHER CHANGES WHATSOEVER)

    [WebMethod]
    public void Junk(ModuleVO vo)
    {
    }

    The my method GetModuleList works absolutely fine!!

    I think the problem is that PersonVO appears in one of the parameter of
    a function. so the serializer knows about it. But ModuleVO doesn't
    (since the return type is an ArrayList now an ModuleVO[])

    the JunkMethod tells the serializer about my ModuleVO object. so then my
    method GetModuleList begins to work as well.

    When I look at my web reference in the object browser, I can see that
    the web reference has proxies for the PersonVO but not for ModuleVO.
    (when the junk method is not there)

    How to overcome the problem? How can I tell the serializer about my
    ModuleVO object. Without the hacking like adding the Junk Method.

    Thanks for your help in advance.

    regards,
    Abhishek.
     
    Abhishek Srivastava, Mar 1, 2004
    #1
    1. Advertising

  2. Abhishek Srivastava

    Dan Rogers Guest

    Hi Abhishek,

    Add the statement

    [XmlInclude(typeof(ModuleVO))]

    at the start of your web service class.

    Regards

    Dan Rogers
    Microsoft Corporation
    --------------------
    >Date: Mon, 01 Mar 2004 15:29:28 +0530
    >From: Abhishek Srivastava <>
    >User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.6)

    Gecko/20040113
    >X-Accept-Language: en-us, en
    >MIME-Version: 1.0
    >Subject: XML Serialization Exception
    >Content-Type: text/plain; charset=us-ascii; format=flowed
    >Content-Transfer-Encoding: 7bit
    >Message-ID: <#bQawM3$>
    >Newsgroups:

    microsoft.public.dotnet.framework.aspnet.webservices,microsoft.public.dotnet
    framework.aspnet
    >NNTP-Posting-Host: atlrel2.hp.com 156.153.255.202
    >Lines: 1
    >Path:

    cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
    8.phx.gbl!TK2MSFTNGP12.phx.gbl
    >Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:214656

    microsoft.public.dotnet.framework.aspnet.webservices:22050
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
    >
    >Hello All,
    >
    >I am writing a XML WebService. I have two very simpilar methods exposed
    >as webService. GetPersonList and GetModuleList.
    >
    >The GetPersonList method returns an ArrayList containing PersonVO(id,
    >name, fullname) object. And GetModuleList returns and ArrayList
    >containing the ModuleVO (id, module name) object.
    >
    >The GetPersonList works absolutely fine. But the GetModule List throws
    >the following exception
    >
    >-------------
    >UT.ServiceUT.GetModuleList : System.Web.Services.Protocols.SoapException
    >: System.Web.Services.Protocols.SoapException: Server was unable to
    >process request. ---> System.InvalidOperationException: There was an
    >error generating the XML document. --->
    >System.InvalidOperationException: The type CommonComponents.ModuleVO was
    >not expected. Use the XmlInclude or SoapInclude attribute to specify
    >types that are not known statically.
    > at
    >System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String
    >name, String ns, Object o, Boolean xsiType)
    > at
    >------------
    >
    >Funny thing is that if I go an add the following method to my asmx.cs
    >file (WITH NO OTHER CHANGES WHATSOEVER)
    >
    >[WebMethod]
    >public void Junk(ModuleVO vo)
    >{
    >}
    >
    >The my method GetModuleList works absolutely fine!!
    >
    >I think the problem is that PersonVO appears in one of the parameter of
    >a function. so the serializer knows about it. But ModuleVO doesn't
    >(since the return type is an ArrayList now an ModuleVO[])
    >
    >the JunkMethod tells the serializer about my ModuleVO object. so then my
    >method GetModuleList begins to work as well.
    >
    >When I look at my web reference in the object browser, I can see that
    >the web reference has proxies for the PersonVO but not for ModuleVO.
    >(when the junk method is not there)
    >
    >How to overcome the problem? How can I tell the serializer about my
    >ModuleVO object. Without the hacking like adding the Junk Method.
    >
    >Thanks for your help in advance.
    >
    >regards,
    >Abhishek.
    >
    >
     
    Dan Rogers, Nov 11, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abhishek Srivastava

    XML Serialization Exception

    Abhishek Srivastava, Mar 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,908
    Abhishek Srivastava
    Mar 1, 2004
  2. Replies:
    8
    Views:
    2,305
    deadsea
    Jan 2, 2005
  3. Replies:
    3
    Views:
    1,082
  4. Dimitri Ognibene
    Replies:
    4
    Views:
    819
    Dimitri Ognibene
    Sep 2, 2006
  5. Ramunas Urbonas
    Replies:
    1
    Views:
    425
    Dino Chiesa [Microsoft]
    Jul 27, 2004
Loading...

Share This Page