invalid cast exception with XmlSerializer

Discussion in 'ASP .Net Web Services' started by jc, Sep 15, 2003.

  1. jc

    jc Guest

    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) )
     
    jc, Sep 15, 2003
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.