【问题标题】:How to make the Asp.Net/WSE asmx page generator add the base class properties in a derived class如何使 Asp.Net/WSE asmx 页面生成器在派生类中添加基类属性
【发布时间】:2009-05-01 04:29:20
【问题描述】:

我有一个带有 2 个公共属性的简单基类 B。这个类被另一个类 D 继承,它添加了另一个公共属性。派生类由 Web 服务调用返回。 ASP.Net 生成的页面如下所示:

'''<remarks/>
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3074"), _
     System.SerializableAttribute(), _
     System.Diagnostics.DebuggerStepThroughAttribute(), _
     System.ComponentModel.DesignerCategoryAttribute("code"), _
     System.Xml.Serialization.XmlTypeAttribute([Namespace]:="")> _
    Partial Public Class D
        Inherits B

        Private guidField As String

        '''<remarks/>
        Public Property Guid() As String
            Get
                Return Me.guidField
            End Get
            Set(ByVal value As String)
                Me.guidField = value
            End Set
        End Property
    End Class

   '''<remarks/>
    <System.Xml.Serialization.XmlIncludeAttribute(GetType(D)), _
     System.Xml.Serialization.XmlIncludeAttribute(GetType(B)), _
     System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3074"), _
     System.SerializableAttribute(), _
     System.Diagnostics.DebuggerStepThroughAttribute(), _
     System.ComponentModel.DesignerCategoryAttribute("code"), _
     System.Xml.Serialization.XmlTypeAttribute([Namespace]:="")> _
    Partial Public MustInherit Class B

        Private nameField As String

        Private descriptionField As String

        '''<remarks/>
        Public Property Name() As String
            Get
                Return Me.nameField
            End Get
            Set(ByVal value As String)
                Me.nameField = value
            End Set
        End Property

        '''<remarks/>
        Public Property Description() As String
            Get
                Return Me.descriptionField
            End Get
            Set(ByVal value As String)
                Me.descriptionField = value
            End Set
        End Property
    End Class

有什么方法可以显示所有公共属性(来自 D 类中的 B 类和 D 类)?只有 D 类对 Web 服务客户端有用,B 类甚至不应该是可见的。 谢谢你

【问题讨论】:

    标签: asp.net web-services inheritance serialization


    【解决方案1】:

    您是否尝试过使用 IncludeInSchema=False 对 B 类使用 XmlTypeAttribute?我不知道这是否可行,但这是可能的。

    XmlTypeAttribute on MSDN for .NET 2.0

    【讨论】:

      【解决方案2】:

      您可以在您的类型上使用XmlSchemaProviderAttribute 并实现一个方法,该方法返回xsd 架构而无需分离基类。这有点工作,但您可以从现有的默认输出开始,并在进入方法实现之前进行一些复制和粘贴工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-25
        • 1970-01-01
        • 1970-01-01
        • 2016-04-29
        相关资源
        最近更新 更多