Hi all.
I have a problem with returning a custom Result object with
webservice.
The classes i use is described below (some fields and properties is
removed)
public class Result {
int statusCode;
object data;
}
public class Customer {
int customerNr
}
public class CustomerList : ArrayList {
//Implements the add method to only add Customer objects
}
And now to the webmethod
[WebMethod]
[XmlInlude(typeof(Customer))]
[XmlInlude(typeof(CustomerList))]
public Result GetCustomers() {
//Logic to find the customer is placed here....
//All the customers is placed in a variable called custList
res.data = custList;
res.statusCode = 1;
return res;
}
Now, when running this, this errormessage appears:
System.InvalidOperationException: The type Result 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.Write3_Object(String
n, String ns, Object o, Boolean isNullable, Boolean needType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_Result(String
n, String ns, Result o, Boolean isNullable, Boolean needType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write10_GetSalesProjectTypesResponse(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()
I also get the same error when trying to just return the CustomerList
and skip the Result object but instead the error says:
System.InvalidOperationException: The type CustomerList may not be
used in this context.
Please help!!!
//Jonas
Dino Chiesa [Microsoft] - 30 Jun 2004 05:51 GMT
this example shows how to return an array of "custom objects"
http://www.winisp.net/cheeso/srcview.aspx?file=Arrays.asmx
-D
> Hi all.
>
[quoted text clipped - 37 lines]
> this context. at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String
> name, String ns, Object o, Boolean xsiType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3
_Object(String
> n, String ns, Object o, Boolean isNullable, Boolean needType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7
_Result(String
> n, String ns, Result o, Boolean isNullable, Boolean needType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1
0_GetSalesProjectTypesResponse(Object[]
> p) --- End of inner exception stack trace --- at
> System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter,
[quoted text clipped - 15 lines]
>
> //Jonas