Webservice复杂类型和类继承

发布于 2024-08-24 19:05:31 字数 1160 浏览 6 评论 0原文

使用以下 Webservice 定义,使用 aClientArgs 作为复杂类型:

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

然后将 aClientArgs 定义为子类:

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

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

返回 save_client args 的以下 WSDL 片段:

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

当我期待以下内容时:

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

所以看来 .NET WebService 没有处理继承属性作为 Web 服务的参数/变量。如何让 .NET 也使用基类的属性?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2024-08-31 19:05:32

您如何确定 WSDL 是错误的?您是否浏览到该服务并单击 save_client 方法的链接?

这只是一个帮助页面。在这种情况下,这是错误的。单击服务描述的链接,我想您会看到以下内容:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文