방법: 웹 서비스에서 상속 사용
이 항목은 레거시 기술과 관련된 것입니다. 이제 XML Web services와 XML Web services 클라이언트는 다음을 사용하여 만들어야 합니다. Windows Communication Foundation.
다음 코드 예제에서는 상속을 사용하여 산술 계산을 수행하는 웹 서비스를 만드는 방법을 보여 줍니다. 이 예제에서는 Design Guidelines for XML Web Services Created Using ASP.NET 항목에서 설명하는 지침 중 하나를 보여 줍니다.
예제
<%@ WebService Language="C#" Class="Add" %>
using System;
using System.Web.Services;
abstract public class MathService : WebService
{
[WebMethod]
abstract public float CalculateTotal(float a, float b);
}
public class Add : MathService
{
[WebMethod]
override public float CalculateTotal(float a, float b)
{
return a + b;
}
}
public class Subtract : MathService
{
[WebMethod]
override public float CalculateTotal(float a, float b)
{
return a - b;
}
}
public class Multiply : MathService
{
[WebMethod]
override public float CalculateTotal(float a, float b)
{
return a * b;
}
}
public class Divide : MathService
{
[WebMethod]
override public float CalculateTotal(float a, float b)
{
if (b==0)
return -1;
else
return a / b;
}
}
<%@ 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