leepowers
leepowers

Reputation: 38308

Webservice complex types and class inheritance

Using the following Webservice definition using aClientArgs as a complex type:

[System.Web.Script.Services.ScriptService]
public class Controller : System.Web.Services.WebService {
    [WebMethod]
    public void save_client(aClientArgs client)
    {
           // Save client data
    }
}

Then defining aClientArgs as a sub-class:

public class aArgs 
{
    public string id = null;
    public string name = null;
}

public class aClientArgs : aArgs
{
    public string address = null;
    public string website = null;
}

Returns the following WSDL fragment for the save_client args:

<save_client xmlns="http://tempuri.org/">
  <client>
    <address>string</address>
    <website>string</website>
  </client>
</save_client>

When I'm expecting the following:

<save_client xmlns="http://tempuri.org/">
  <client>
    <id>string</id>
    <name>string</name>
    <address>string</address>
    <website>string</website>
  </client>
</save_client>

So it appears that the .NET WebService is not treating inherited properties as arguments/variables for purposes of a web service. How do I get .NET to also use the properties of the base class?

Upvotes: 2

Views: 3923

Answers (1)

John Saunders
John Saunders

Reputation: 161773

How did you determine that the WSDL is wrong? Did you browse to the service and click the link for the save_client method?

That's just a help page. In this case, it's wrong. Click the link for the service description, and I think you'll see the following:

  <s:complexType name="aClientArgs">
    <s:complexContent mixed="false">
      <s:extension base="tns:aArgs">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="Address" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="Website" type="s:string" />
        </s:sequence>
      </s:extension>
    </s:complexContent>
  </s:complexType>
  <s:complexType name="aArgs">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="ID" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" />
    </s:sequence>
  </s:complexType>

Upvotes: 2

Related Questions