need help returning webservice data in arraylist...

Discussion in 'ASP .Net Web Services' started by Milsnips, Sep 2, 2004.

  1. Milsnips

    Milsnips Guest

    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.
     
    Milsnips, Sep 2, 2004
    #1
    1. Advertising

  2. 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
     
    Elena Kharitidi, Sep 3, 2004
    #2
    1. Advertising

  3. Milsnips

    Milsnips Guest

    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" <> wrote in message
    news:...
    > 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, Sep 3, 2004
    #3
  4. 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
     
    Elena Kharitidi, Sep 23, 2004
    #4
    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. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,786
    Natty Gur
    Aug 19, 2003
  2. Kaidi
    Replies:
    4
    Views:
    2,465
    Kaidi
    Jan 3, 2004
  3. xz
    Replies:
    16
    Views:
    2,426
  4. Philipp
    Replies:
    6
    Views:
    955
    Arne Vajhøj
    May 28, 2008
  5. Molalla Attenborough

    Need help returning data from a vb.net webservice please

    Molalla Attenborough, Dec 29, 2003, in forum: ASP .Net Web Services
    Replies:
    7
    Views:
    564
    Patrick Wenzel
    Dec 31, 2003
Loading...

Share This Page