Microsoft KB Archive/326792

= PRB: Web Services XmlInclude Does Not Work on Enumerations =

Article ID: 326792

Article Last Modified on 9/22/2003

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Web Services Enhancements for Microsoft .NET 2.0

-



This article was previously published under Q326792



SYMPTOMS
You have an enumeration in your Web service, but it is not used as a parameter or return type for any of the Web methods. You want the enumeration definition to be included in the Web Services Description Language (WSDL) document for the Web service, so you try to use XmlInclude, as follows: public class MyWebService : WebService {      public enum MyEnum {       Item1, Item2, Item3 }

[XmlInclude(typeof(MyEnum))] [WebMethod] public string HelloWorld {                  return &quot;Hello World&quot;; } } However, the generated WSDL document or the proxy does not include the enumeration definition.



CAUSE
The XmlInclude attribute is currently intended to support polymorphic return types. In other words, it is intended to permit you to mark a Web method as returning a base class, but also include the definitions for the derived classes in the WSDL document so that clients can be prepared to accept objects of the derived types as return values.



RESOLUTION
Add a class that has a public property of the type of your enumeration. Use XmlInclude to include the definition for this class in the WSDL document. When you do this, the definition for the enumeration is also included.

NOTE: At least one of your Web methods must have a return type of object. For example: public class MyWebService : WebService {          public enum MyEnum {           Item1, Item2, Item3 }

class MyEnumWrapper {           public MyEnum dummy; }

[XmlInclude(typeof(MyEnumWrapper))] [WebMethod] public object HelloWorld {                      return &quot;Hello World&quot;; }   }



STATUS
This behavior is by design.

Keywords: kbprb kbpending KB326792

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.