RE: web service error - urgent



What is "ports" anyway? I don't see this defined anywhere in your method.
(return ports;)?

What about this instead (return an array of Cars):
return carList.ToArray(typeof(Car));


--
rgds.
/Claus Konrad
MCSD.NET (C#)


"igotyourdotnet" wrote:

I'm creating a web service this is going to return an arraylist of items.
When I try and run it Im' getting the following error message:
System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidOperationException: The type Car List 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.Write3_ArrayOfAnyType(Object o)
at
Microsoft.Xml.Serialization.GeneratedAssembly.ArrayListSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
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()


here is my code Im' trying to use.
[WebMethod]
[return: System.Xml.Serialization.XmlArrayItem(typeof(Cars))]
public ArrayList CarList
{
string sql = "SELECT * from Cars";
SqlConnection conn = new
SqlConnection(ConfigurationManager.AppSettings["connectMe"]);
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader reader;
reader = cmd.ExecuteReader();

ArrayList carList= new ArrayList();
while (reader.Read())
{
Cars car = new Cars
car.make= eader.GetString(1);
car.model= reader.GetString(2);
carList.Add(car)
}
reader.Close();
conn.Close();

return ports;
}

public class Cars
{
public string make;
public string cars;
}

what am i missing or doing wrong?
.



Relevant Pages

  • Re: Accelerating rocket/light beam question
    ... There is a string connecting the two cars. ... Think, for a moment, about a system consisting of two rockets B and C ... F be the frame of your cars. ...
    (sci.physics.research)
  • Serialization of a custom collection
    ... public class CarCollection: List ... private string errMsg; ... CarCollection cars = GetCars; ... How to properly enhance my custom collection? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Fast and Safe C Strings: User friendly C macros to Declare and use C Strings.
    ... Those that say there isn't a problem, and that it is the programmer's fault perhaps have forgotten that seat belts were introduced into cars to protect people if an accident happens. ... And it is precisely because drivers do cause accidents, we have safer cars. ... And for those people that suggest that C does have a string type, I would suggest that it doesn't, compared with Pascal, PL/I, COBOL or even Assembler. ...
    (comp.lang.c)
  • Re: session variable issue?
    ... You are never assigning Sessionto anything. ... You are setting the string "cars" to 'Y', but since never assign the Session ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: web service error - urgent
    ... When I try and run it Im' getting the following error message: ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... Cars car = new Cars ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)