need help returning webservice data in arraylist...
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.webservices.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Milsnips
hi there,

i have a webservice which my function calls a database( eg. customer table),
what i have is my own Customer class, and i want to return an array of my
"Customer" objects.

here is my code i use (c.GetList returns an arraylist of customer objects
from the database:

<WebMethod()> _

Function GetClientList() As ArrayList

Dim c As New getAway.Client

Return c.GetList()

End Function

when i run it, it returns the following error:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidOperationException: The type getAway.Client 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
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1
_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5
_ArrayOfAnyType(Object o)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse
response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[]
returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[]
returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()

any help appreciated!

thanks,
Paul.

Reply to this message...
 
    
Elena Kharitidi (VIP)
When an un-typed array is returned from a web method, customer has to
specify (via custom serialization attributes) objects of what type can be
expected as items, this can be done by adding custom serialization
attributes to the return type:

(1)
Imports System.Xml.Serialization

<WebMethod()> _
Function GetClientList() As <XmlElement(GetType(getAway.Client))> ArrayList
Dim c As New getAway.Client
Return c.GetList()
End Function

Or by adding XmlInclude attribute to the service class:

(2)
Imports System.Xml.Serialization

<XmlInclude(GetType(getAway.Client))> _
Public Class ADSearcher
End Class

Please note that you need to do only on of the two, and depending on which
one you choose, the schema (and wire signature) of your method will be
different.
Personally I like the first approach better: it provides better
strongly-typed programming model on the client.

Thanks,
Elena

Reply to this message...
 
    
Milsnips
thanks for your help.

I added the first example, but it still returns an error.
when i run my "asmx" page and select the GetClientList webservice, the soap
response looks fine, as it displays the client object, but the HTTP post
response example shows 'AnyType"

it still returns the same error as mentioned in the first post.

any ideas?

thanks
Paul.

"Elena Kharitidi" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Collections.ArrayList
System.InvalidOperationException
System.IO.TextWriter
System.Web.HttpResponse
System.Xml.Serialization.XmlSerializationWriter
System.Xml.Serialization.XmlSerializer
System.Xml.Serialization.XmlSerializerNamespaces
System.Xml.XmlElement
System.Xml.XmlWriter




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com