Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > XML Serialization Exception

Reply
Thread Tools

XML Serialization Exception

 
 
Abhishek Srivastava
Guest
Posts: n/a
 
      03-01-2004
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.Wr iteTypedPrimitive(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.

 
Reply With Quote
 
 
 
 
Dan Rogers
Guest
Posts: n/a
 
      11-11-2004
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 <(E-Mail Removed)>
>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$(E-Mail Removed)>
>Newsgroups:

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

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

microsoft.public.dotnet.framework.aspnet.webservic es:22050
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservic es
>
>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.W riteTypedPrimitive(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.
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to move from java object serialization to xml serialization? Dimitri Ognibene Java 4 09-02-2006 07:32 AM
Object serialization XML vs java serialization plasticfloor@gmail.com Java 3 06-14-2006 03:45 AM
Serialization Problems and books on serialization? sinleeh@hotmail.com Java 8 01-02-2005 02:40 PM
avoiding XML serialization, different WSDL generation, soap serialization Ramunas Urbonas ASP .Net Web Services 1 07-27-2004 09:57 PM
XML Serialization Exception Abhishek Srivastava ASP .Net 0 03-01-2004 09:59 AM



Advertisments