ASP.NET Web Services documentation and derived classes

1 minute read

This is another gotcha that I ran into this week. The documentation pages generated by the ASMX engine don’t seem to handle derived/base class types correctly. To illustrate this problem, create a demo .asmx file with the following contents:

<%@ WebService Language="c#" Class="MyService" %>

public class MyBase {
    public int baseVal = 5;

public class MyDerived : MyBase {
    public int derivedVal = 10;

public class MyService {
    public MyDerived MyTest() {
        return new MyDerived();

The generated WSDL correctly contains the type definitions for MyBase and MyDerived:

<s:complexType name="MyDerived">
  <s:complexContent mixed="false">
    <s:extension base="s0:MyBase">
        <s:element minOccurs="1" maxOccurs="1" name="derivedVal" type="s:int" /> 
<s:complexType name="MyBase">
    <s:element minOccurs="1" maxOccurs="1" name="baseVal" type="s:int" /> 

And the implementation of the method returns the correct result:

<?xml version="1.0" encoding="utf-8" ?> 
<MyDerived xmlns:xsd=""

But the examples in the generated documentation page only show the members from the derived class:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
    <MyTestResponse xmlns="">

Note that only <derivedVal> is shown in the documentation and <baseVal> is missing. I spent a little while looking at this before I realised that it was just the documentation page and that the schema was correct.