PRB: Web Services XmlInclude Does Not Work on Enumerations (326792)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Web Services (included with the .NET Framework) 1.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 "Hello World";
	}
}
				
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 "Hello World";
		}
	}
				

STATUS

This behavior is by design.

Modification Type:MajorLast Reviewed:9/22/2003
Keywords:kbpending kbprb KB326792