invalid cast exception with XmlSerializer

J

jc

I have the following web method in which I fill a typed dataset :

[WebMethod]
[return: XmlElement(typeof(Employees[]))]
public XmlDataDocument GetEmployeesTypedXML()
{
sqlDataAdapter1.Fill(employeesDS1);
XmlDataDocument doc = new XmlDataDocument(employeesDS1);
return doc;
}

I want to return an array of Employees object :

public class Employees
{
public int EmployeeID;
public string LastName;
}

hence the [return...] attribute.
But the client receive this exception :

Additional information: System.Web.Services.Protocols.SoapException: Server
was unable to process request. ---> System.InvalidOperationException: There
was an error generating the XML document. ---> System.InvalidCastException:
Specified cast is not valid.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1
2_GetEmployeesTypedXMLResponse(Object[] p)
--- 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.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[]
returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[]
returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- End of inner exception stack trace ---


Any idea ?
(in fact I'm just trying to reproduce the example in :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service02112003.asp (bottom) )
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top