IList deserialization

Discussion in 'ASP .Net Web Services' started by Vladner, Apr 4, 2007.

  1. Vladner

    Vladner Guest

    I have a class with a property of IList type and a webmethod with parameter
    of this class.
    When I try to invoke the webmethod passing an instance of this class, I
    receive the error below.

    System.Web.Services.Protocols.SoapException: Server was unable to read
    request. ---> System.InvalidOperationException: There is an error in the XML
    document. ---> System.InvalidOperationException: Could not deserialize
    global::System.Collections.IList. Parameterless constructor is required for
    collections and enumerators.
    at
    Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read9_Operador(Boolean isNullable, Boolean checkType)
    at
    Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read33_localizarOperador()
    at
    Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer36.Deserialize(XmlSerializationReader reader)
    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
    xmlReader, String encodingStyle, XmlDeserializationEvents events)
    --- End of inner exception stack trace ---
    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
    xmlReader, String encodingStyle, XmlDeserializationEvents events)
    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
    xmlReader, String encodingStyle)
    at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
    --- End of inner exception stack trace ---
    at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
    at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

    Any Ideas ?

    Vládner
     
    Vladner, Apr 4, 2007
    #1
    1. Advertising

  2. "Vladner" <> wrote in message
    news:D...
    >I have a class with a property of IList type and a webmethod with parameter
    > of this class.
    > When I try to invoke the webmethod passing an instance of this class, I
    > receive the error below.

    ....
    > Any Ideas ?


    There are no instances of interfaces. There are instances of classes which
    implement an interface, but there are no instances of interfaces.

    If there is no instance, then you can't serialize it!

    John

    P.S. You should consider not passing platform-specific types as parameters
    or return values of web services. Even if you intend to stick with Windows
    clients only today, in the future you might need to support something like
    PHP or Perl.
     
    John Saunders, Apr 4, 2007
    #2
    1. Advertising

  3. Vladner

    Vladner Guest

    Actually, the serialization is of the object that has a property of IList
    type. In VS2003 (Framework 1.1) the same example works fine. I think this is
    something different in framework 2.0 (VS 2005). The compilation passes, but a
    runtime error ocurrs at the Webmethod call.

    About the use of specific types... I'm responsible for an evaluation of a
    migration from VS2003 to VS2005. So, the situation appeared in one of chosen
    legacy system.

    I created an separate solution for simulation:

    There are two projects: A WebService and a WebApplication. The Webservice
    has a class named Customer with a property of IList type and a WebMethod that
    just receive as parameter one instance of Customer. The client has just a
    call of the Webmethod passing one instance of this class.

    I'm posting codes that simulate the error.

    **** WebMethod ******************

    [WebMethod]
    public void GetCust(Customer c){

    }

    **** Customer class - WebService Project ****

    public class Customer
    {
    public Cliente()
    {
    }
    private string strName;
    private IList lstFriends;

    public string Name
    {
    get
    {
    return strName;
    }
    set
    {
    this.strName= value;
    }
    }

    public IList Friends
    {
    get
    {
    return lstFriends;
    }
    set
    {
    this.lstFriends = value;
    }
    }

    }

    **** Page_load - WebApplication****

    localhost.Service1 srv = new localhost.Service1();
    localhost.Customer c = new localhost.Customer();

    srv.GetCust(c);


    P.S.: If, instead of the IList, I use ArrayList as a property type
    everything works fine.

    Vladner


    "John Saunders" wrote:

    > "Vladner" <> wrote in message
    > news:D...
    > >I have a class with a property of IList type and a webmethod with parameter
    > > of this class.
    > > When I try to invoke the webmethod passing an instance of this class, I
    > > receive the error below.

    > ....
    > > Any Ideas ?

    >
    > There are no instances of interfaces. There are instances of classes which
    > implement an interface, but there are no instances of interfaces.
    >
    > If there is no instance, then you can't serialize it!
    >
    > John
    >
    > P.S. You should consider not passing platform-specific types as parameters
    > or return values of web services. Even if you intend to stick with Windows
    > clients only today, in the future you might need to support something like
    > PHP or Perl.
    >
    >
    >
     
    Vladner, Apr 5, 2007
    #3
    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. frank

    Implement IList Interface

    frank, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    569
    frank
    Jul 11, 2003
  2. DaveF

    Need to pass a method an Ilist

    DaveF, Dec 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    323
    Karl Seguin
    Dec 8, 2004
  3. Flip
    Replies:
    1
    Views:
    475
    Brock Allen
    Mar 28, 2005
  4. =?Utf-8?B?Tmljaw==?=
    Replies:
    6
    Views:
    25,043
    =?Utf-8?B?Tmljaw==?=
    Jul 19, 2006
  5. bruce barker
    Replies:
    1
    Views:
    449
    =?Utf-8?B?VFo=?=
    Dec 19, 2006
Loading...

Share This Page