开发者

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 we开发者_StackOverflow中文版bsite = 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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜