RE: web service error - urgent
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Mon, 13 Nov 2006 02:25:29 GMT
{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fprq2\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang2052\f0\fs20 Hi Mike,
\par
\par Your original code is correct, you should return the ArrayList instance rather than the ArrayList.ToArray since your method's signature has marked the return type as "ArrayList".
\par
\par For your original problem
\par ===========
\par System.InvalidOperationException: The type Car List was not
\par expected. Use the XmlInclude or SoapInclude attribute to specify types that
\par are not known statically.
\par ===========
\par
\par As the error message indicate, you should add the "XmlInclude" attribute to specify the "Cars" type (or any other derived class type from Object you will add into ArrayList). For example:
\par
\par ====================
\par [WebMethod]
\par [XmlInclude(typeof(Cars))]
\par [return: XmlArrayItem(typeof(Cars))]
\par public ArrayList CarList()
\par \{
\par ArrayList list = new ArrayList();
\par
\par for (int i = 0; i < 5; i++)
\par \{
\par Cars car = new Cars();
\par car.cars = "cars_" + i;
\par car.make = "make_" + i;
\par
\par list.Add(car);
\par \}
\par
\par return list;
\par \}
\par ======================
\par
\par You can also add the XmlInclude attribute at class level such as below so that all the webmethods in the class can get this applied.
\par
\par =========
\par [XmlInclude(typeof(Cars))]
\par public class ArrayListService : System.Web.Services.WebService
\par \{
\par =========
\par
\par This attribute is to make the XMLSerialization for a class or a method be aware of some certain derived object types.
\par
\par Hope this helps some.
\par
\par Sincerely,
\par
\par Steven Cheng
\par
\par Microsoft MSDN Online Support Lead
\par
\par
\par
\par ==================================================
\par
\par Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notifications.
\par
\par
\par
\par Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx.
\par
\par ==================================================
\par
\par
\par
\par This posting is provided "AS IS" with no warranties, and confers no rights.
\par
\par
\par }
- References:
- web service error - urgent
- From: igotyourdotnet
- RE: web service error - urgent
- From: Claus Konrad [MCSD]
- RE: web service error - urgent
- From: igotyourdotnet
- web service error - urgent
- Prev by Date: WebReference and ServiceDescriptionImporter failing to generate code
- Next by Date: Any decent book on WCF (Indigo)?
- Previous by thread: RE: web service error - urgent
- Next by thread: RE: web service error - urgent
- Index(es):
Loading