Export (0) Print
Expand All

How to: Use Inheritance in a Web Service

This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation .

The following code example demonstrates how to use inheritance to create a Web service that performs math calculations. This example illustrates one of the guidelines explained in the topic, Design Guidelines for XML Web Services Created Using ASP.NET.

Example

<%@ WebService Language="VB" Class="Add" %>
Imports System
Imports System.Web.Services
MustInherit Public Class MathService : Inherits WebService    
    <WebMethod> _
    Public MustOverride Function CalculateTotal(a As Single, _
                        b As Single) As Single
End Class
Public Class Add : Inherits MathService    
    <WebMethod> _
    Public Overrides Function CalculateTotal(a As Single, _
                     b As Single) As Single
        Return a + b
    End Function
End Class 
Public Class Subtract : Inherits MathService
    <WebMethod> _
    Public Overrides Function CalculateTotal(a As Single, _
                     b As Single) As Single
        Return a - b
    End Function
End Class 
Public Class Multiply : Inherits MathService
    <WebMethod> _
    Public Overrides Function CalculateTotal(a As Single, _
                     b As Single) As Single
        Return a * b
    End Function
End Class 
Public Class Divide : Inherits MathService
    <WebMethod> _
    Public Overrides Function CalculateTotal(a As Single, _
                     b As Single) As Single
        If b = 0 Then
            Return - 1
        Else
            Return a / b
        End If
    End Function
End Class

See Also

Community Additions

ADD
Show:
© 2014 Microsoft