IList deserialization

V

Vladner

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
 
J

John Saunders

Vladner said:
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.
 
V

Vladner

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top