This is a discussion on why the "InvalidOperationException" error when returning array value in webservice? within the ASP and ASP.NET Programming forums, part of the Web Development category; I have a database result set I would like to return, so I create a new array for each row, ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| I have a database result set I would like to return, so I create a new array for each row, and the rows into an arraylist Now when I compile it it works fine, but when I go to test out the web service it returns this nice message. |
| Sponsored Links |
| |||
| The error is... Code: System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.String[] may not be used in this context. 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() |
| |||
| Can you put here your code here?
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Ya sure… Here is my code… Code: [WebMethod]
public ArrayList getResults()
{
string sql = "select * from tblreadings";
MySqlCommand myCommand = new MySqlCommand(sql, this.con);
con.Open();
MySqlDataReader myReader;
myReader = myCommand.ExecuteReader();
string[] columns = null;
// Fields in a row are stored in array
int fieldCount = myReader.FieldCount;
// Rows are stored in arraylist
ArrayList rows = new ArrayList();
//string results = "";
try
{
while (myReader.Read())
{
columns = new string[fieldCount - 1];
columns[0] = myReader.GetString(1);
columns[1] = myReader.GetString(2);
columns[2] = myReader.GetString(3);
rows.Add(columns);
}
}
finally
{
myReader.Close();
con.Close();
}
return rows;
} |
| |||
| Where are you declaring the size of the array? What you should probably do here is make a simple data object to contain the data then use a List<YourSimpleDataObject> rather than an array list of arrays. It will be much more readable on the wire.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Hi, The size of the array is declared in here: Code: columns = new string[fieldCount - 1]; The size of the array is set to the number of columns. I'd like to know why an arraylist of arrays wasn't able to be xmlserialized when both an arraylist and array can be xmlserialized individually. |
| |||
| Hi buddy, Because the ArrayList is untyped, so ASP.NET has no way of knowing what type the elements will be. Hence, it cannot generate a schema for the type. Either use a type which is specific about its elements -or- Use an attribute to instruct ASP.NET about the type of the elements A dataset is a concrete type - one for which ASP.NET *can* generate a schema. Indeed, a dataset definition *is* a schema.
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I keep getting "Data Missing" when I click the "back" button in my browser. How can I | oxygen | HTML, CSS and Javascript Coding Techniques | 1 | 07-28-2007 01:12 AM |
| Difference between "vector" and "array"? | Sabari | C and C++ Programming | 1 | 07-24-2007 04:33 AM |
| I get the error message "Unable to start debugging on the web server..." when I debug | oxygen | ASP and ASP.NET Programming | 1 | 07-20-2007 04:50 AM |
| I get the error "The page cannot be displayed" and an HTTP 502 Proxy Error. Why? | kingmaker | ASP and ASP.NET Programming | 1 | 07-20-2007 04:43 AM |
| Why do I get "HTTP 500" error(or "(DLL)initialization routine failed")in my browser? | kingmaker | ASP and ASP.NET Programming | 1 | 07-20-2007 04:38 AM |