Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need help returning webservice data in arraylist...

1 view
Skip to first unread message

Milsnips

unread,
Sep 2, 2004, 9:00:33 AM9/2/04
to
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.


Elena Kharitidi

unread,
Sep 2, 2004, 9:19:39 PM9/2/04
to
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

Milsnips

unread,
Sep 3, 2004, 6:29:53 AM9/3/04
to
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" <ele...@online.microsoft.com> wrote in message
news:CPIynPVk...@cpmsftngxa10.phx.gbl...

Elena Kharitidi

unread,
Sep 23, 2004, 1:00:41 PM9/23/04
to
Sorry about the misinformation:
There is known bug in .Net Framework preventing using XmlElement attribute
on the return array.
I am afraid you have to use XmlInclude attribute instead.
Also note that is you intend return more then one type of object, all of
them have to be listed:

<System.Web.Services.WebServiceAttribute([Namespace]:="http://tempuri.org/")
, _
System.Web.Services.WebServiceBindingAttribute(Name:="TestSoap",
[Namespace]:="http://tempuri.org/"), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(MyClass1)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(MyClass2)), _
System.Xml.Serialization.XmlIncludeAttribute(GetType(Object()))> _
Public Class MyWebService
<System.Web.Services.WebMethodAttribute()> _
Public Function GetClientList () As ArrayList
End Function
End Class

Thanks,
Elena


0 new messages