방법: 비동기 웹 서비스 메서드 만들기

이 항목은 레거시 기술과 관련된 것입니다. 이제 XML Web services와 XML Web services 클라이언트는 다음을 사용하여 만들어야 합니다. Windows Communication Foundation.

다음 절차에서는 웹 서비스 메서드를 비동기 액세스를 위한 메서드 쌍으로 변환하는 방법을 설명합니다. 이 절차는 .NET Framework 비동기 디자인 패턴을 따릅니다. 비동기 XML Web services 메서드 항목에서는 이 절차를 수행하는 방법과 Wsdl.exe 도구를 사용하여 동기 액세스용으로 디자인된 웹 서비스 메서드에도 비동기적으로 액세스할 수 있는 클라이언트 프록시 클래스를 생성하는 방법에 대해 설명합니다.

비동기 웹 서비스 메서드를 구현하려면

  1. 비동기 웹 서비스 메서드를 동일한 기본 이름에 각각 Begin과 End가 앞에 붙은 두 개의 메서드로 분할합니다.

  2. Begin 메서드의 매개 변수 목록에는 메서드의 기능에 대한 모든 in 및 by 참조 매개 변수와 두 개의 추가 매개 변수가 포함됩니다.

    • By reference 매개 변수는 in 매개 변수로 나열됩니다.

    • 끝에서 두 번째 매개 변수는 AsyncCallback입니다. 클라이언트에서는 AsyncCallback 매개 변수를 사용하여 메서드 완료 시 호출되는 대리자를 제공할 수 있습니다. 비동기 웹 서비스 메서드가 다른 비동기 메서드를 호출하면 이 매개변수가 해당 메서드의 끝에서 두 번째 매개 변수에 전달됩니다.

    • 마지막 매개 변수는 Object입니다. 호출자는 Object 매개 변수를 사용하여 메서드에 상태 정보를 제공할 수 있습니다. 비동기 웹 서비스 메서드가 다른 비동기 메서드를 호출하면 이 매개변수가 해당 메서드의 마지막 매개 변수에 전달됩니다.

    • 반환 값은 IAsyncResult 형식이어야 합니다.

  3. End 메서드의 매개 변수 목록은 IAsyncResult와 해당 메서드 기능에 대한 outbyreference 매개 변수로 구성됩니다.

    • 반환 값은 비동기 웹 서비스 메서드의 반환 값과 같은 형식입니다.

    • By reference 매개 변수가 out 매개 변수로 나열됩니다.

예제

using System;
using System.Web.Services;

[WebService(Namespace="https://www.contoso.com/")]
public class MyService : WebService 
{
    public RemoteService remoteService;
    public MyService() 
    {
        // Create a new instance of proxy class for 
        // the Web service to be called.
        remoteService = new RemoteService();
    }
    // Define the Begin method.
    [WebMethod]
    public IAsyncResult BeginGetAuthorRoyalties(String Author,
        AsyncCallback callback, object asyncState) 
    {
        // Begin asynchronous communictation with a different XML Web
        // service.
        return remoteService.BeginReturnedStronglyTypedDS(Author,
            callback,asyncState);
    }
    // Define the End method.
    [WebMethod]
    public AuthorRoyalties EndGetAuthorRoyalties(IAsyncResult
        asyncResult) 
    {
        // Return the asynchronous result from the other Web service.
        return remoteService.EndReturnedStronglyTypedDS(asyncResult);
    }
}
Imports System.Web.Services
<WebService(Namespace:="https://www.contoso.com/")> _
Public Class MyService
    Inherits WebService
    Public remoteService As RemoteService

    Public Sub New()
        MyBase.New()
        ' Create a new instance of proxy class for 
        ' the Web service to be called.
        remoteService = New RemoteService()
    End Sub

    ' Define the Begin method.
    <WebMethod()> _
    Public Function BeginGetAuthorRoyalties(ByVal Author As String, _
    ByVal callback As AsyncCallback, ByVal asyncState As Object) _
        As IAsyncResult
        ' Begin asynchronous communictation with a different XML Web
        ' service.
        Return remoteService.BeginReturnedStronglyTypedDS(Author, _
            callback, asyncState)
    End Function
    ' Define the End method.
    <WebMethod()> _
    Public Function EndGetAuthorRoyalties(ByVal asyncResult As _
        IAsyncResult) As AuthorRoyalties
        ' Return the asynchronous result from the other Web service.
        Return remoteService.EndReturnedStronglyTypedDS(asyncResult)
    End Function
End Class

참고 항목

작업

방법: 웹 서비스 메서드를 사용하여 비동기 호출 연결

개념

비동기 XML Web services 메서드
XML Web services와 비동기적으로 통신