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.
(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
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...
<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