I wonder how to return a list of objects instead of a list of strings?
Returning a list of strings works, but when I replace everything by an object it fails..
Here's my Web Service
[WebMethod]
public List<OpProduct> SearchProduct(string name) {
BLProduct blProduct = new BLProduct();
List<OpProduct> result = byproduct.SearchProducts(name);
return result;
}
And here's my Business Logic Layer
public List<OpProduct> SearchProducts(string name)
{
List<OpProduct> result = (from item in db.OpProducts where item.Name.StartsWith(name) select item).ToList<OpProduct>();
return result;
}
And here's my error message (sorry, could not translate this)
System.InvalidOperationException: Er is een fout opgetreden bij het genereren van het XML-document. ---> System.InvalidOperationException: Er is een kringverwijzing aangetroffen tijdens het toepassen van serialisatie op een object van het type OpProduct. bij System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns) bij Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write9_OpProduct(String n, String ns, OpProduct o, Boolean isNullable, Boolean needType)
bij Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5_OpGeheugen(String n, String ns, OpGeheugen o, Boolean isNullable, Boolean needType)
bij Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write9_OpProduct(String n, String ns, OpProduct o, Boolean isNullable, Boolean needType)
bij Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write10_ArrayOfOpProduct(Object o) bij Microsoft.Xml.Serialization.GeneratedAssembly.ListOfOpProductSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer) bij System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) --- Einde van intern uitzonderingsstackpad --- bij System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) bij System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces) bij System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue) bij System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream) bij System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues) bij System.Web.Services.Protocols.WebServiceHandler.Invoke()
Can anyone help me?