SoapHttpClientProtocol.BeginInvoke 메서드

정의

SOAP를 사용하여 XML Web services의 비동기 호출을 시작합니다.

protected:
 IAsyncResult ^ BeginInvoke(System::String ^ methodName, cli::array <System::Object ^> ^ parameters, AsyncCallback ^ callback, System::Object ^ asyncState);
protected IAsyncResult BeginInvoke (string methodName, object[] parameters, AsyncCallback callback, object asyncState);
member this.BeginInvoke : string * obj[] * AsyncCallback * obj -> IAsyncResult
Protected Function BeginInvoke (methodName As String, parameters As Object(), callback As AsyncCallback, asyncState As Object) As IAsyncResult

매개 변수

methodName
String

BeginInvoke(String, Object[], AsyncCallback, Object) 메서드를 호출하고 있는 파생 클래스의 XML Web services 메서드 이름입니다.

parameters
Object[]

XML 웹 서비스에 전달할 매개 변수가 들어 있는 개체의 배열입니다. 배열 내의 값 순서는 파생 클래스의 호출 메서드에 있는 매개 변수의 순서와 일치합니다.

callback
AsyncCallback

비동기 호출이 완료될 때 호출할 대리자입니다. callbacknull이면 대리자가 호출되지 않습니다.

asyncState
Object

호출자가 제공한 추가 정보입니다.

반환

IAsyncResult

원격 메서드 호출에서 반환 값을 가져오기 위해 IAsyncResult 메서드에 전달된 EndInvoke(IAsyncResult)입니다.

예외

서버 컴퓨터에 요청이 도달했지만 성공적으로 처리되지 않은 경우

요청은 개체의 현재 상태에서 유효하지 않습니다.

네트워크에 액세스하는 동안 오류가 발생한 경우.

예제

다음 코드 예제는 XML 웹 서비스에 대 한 웹 서비스 설명 언어 도구 (Wsdl.exe)에 Math 의해 생성 된 프록시 클래스입니다. BeginAdd 프록시 클래스 BeginInvoke 의 메서드 내에서 메서드는 XML 웹 서비스 메서드에 대한 비동기 호출을 Add 시작합니다.

#using <System.Web.Services.dll>
#using <System.Xml.dll>
#using <System.dll>

using namespace System::Diagnostics;
using namespace System::Xml::Serialization;
using namespace System;
using namespace System::Web::Services::Protocols;
using namespace System::Web::Services;

namespace MyMath
{

   [System::Web::Services::WebServiceBindingAttribute(Name="MyMathSoap",Namespace="http://www.contoso.com/")]
   public ref class MyMath: public System::Web::Services::Protocols::SoapHttpClientProtocol
   {
   public:

      [System::Diagnostics::DebuggerStepThroughAttribute]
      MyMath()
      {
         this->Url = "http://www.contoso.com/math.asmx";
      }


      [System::Diagnostics::DebuggerStepThroughAttribute]
      [System::Web::Services::Protocols::SoapDocumentMethodAttribute("http://www.contoso.com/Add",
      RequestNamespace="http://www.contoso.com/",ResponseNamespace="http://www.contoso.com/",
      Use=System::Web::Services::Description::SoapBindingUse::Literal,
      ParameterStyle=System::Web::Services::Protocols::SoapParameterStyle::Wrapped)]
      int Add( int num1, int num2 )
      {
         array<Object^>^temp1 = {num1,num2};
         array<Object^>^results = this->Invoke( "Add", temp1 );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }


      [System::Diagnostics::DebuggerStepThroughAttribute]
      System::IAsyncResult^ BeginAdd( int num1, int num2, System::AsyncCallback^ callback, Object^ asyncState )
      {
         array<Object^>^temp2 = {num1,num2};
         return this->BeginInvoke( "Add", temp2, callback, asyncState );
      }


      [System::Diagnostics::DebuggerStepThroughAttribute]
      int EndAdd( System::IAsyncResult^ asyncResult )
      {
         array<Object^>^results = this->EndInvoke( asyncResult );
         return  *dynamic_cast<int^>(results[ 0 ]);
      }

   };

}


namespace MyMath {
    using System.Diagnostics;
    using System.Xml.Serialization;
    using System;
    using System.Web.Services.Protocols;
    using System.Web.Services;

    [System.Web.Services.WebServiceBindingAttribute(Name="MyMathSoap", Namespace="http://www.contoso.com/")]
    public class MyMath : System.Web.Services.Protocols.SoapHttpClientProtocol {

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public MyMath() {
            this.Url = "http://www.contoso.com/math.asmx";
        }

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace="http://www.contoso.com/", ResponseNamespace="http://www.contoso.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
        public int Add(int num1, int num2) {
            object[] results = this.Invoke("Add", new object[] {num1,
                        num2});
            return ((int)(results[0]));
        }

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public System.IAsyncResult BeginAdd(int num1, int num2, System.AsyncCallback callback, object asyncState) {
            return this.BeginInvoke("Add", new object[] {num1,
                        num2}, callback, asyncState);
        }

        [System.Diagnostics.DebuggerStepThroughAttribute()]
        public int EndAdd(System.IAsyncResult asyncResult) {
            object[] results = this.EndInvoke(asyncResult);
            return ((int)(results[0]));
        }
    }
}

Option Strict On
Option Explicit On

Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

Namespace MyMath
    
    <System.Web.Services.WebServiceBindingAttribute(Name:="MyMathSoap", [Namespace]:="http://www.contoso.com/")>  _
    Public Class MyMath
        Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Sub New()
            MyBase.New
            Me.Url = "http://www.contoso.com/math.asmx"
        End Sub
        
        <System.Diagnostics.DebuggerStepThroughAttribute(),  _
         System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.contoso.com/Add", RequestNamespace:="http://www.contoso.com/", ResponseNamespace:="http://www.contoso.com/", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)>  _
        Public Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
            Dim results() As Object = Me.Invoke("Add", New Object() {num1, num2})
            Return CType(results(0),Integer)
        End Function
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Function BeginAdd(ByVal num1 As Integer, ByVal num2 As Integer, ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
            Return Me.BeginInvoke("Add", New Object() {num1, num2}, callback, asyncState)
        End Function
        
        <System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Public Function EndAdd(ByVal asyncResult As System.IAsyncResult) As Integer
            Dim results() As Object = Me.EndInvoke(asyncResult)
            Return CType(results(0),Integer)
        End Function
    End Class
End Namespace

다음 코드 예제는 이전 프록시 클래스를 만든 XML 웹 서비스입니다 Math .

<%@ WebService Language="C#" Class="MyMath"%>
 using System.Web.Services;
 using System;
 
 [WebService(Namespace="http://www.contoso.com/")] 
 public class MyMath {

    [ WebMethod ]
    public int Add(int num1, int num2) {
        return num1+num2;
    }
 }
<%@ WebService Language="VB" Class="MyMath"%>
Imports System.Web.Services
Imports System

<WebService(Namespace:="http://www.contoso.com/")> _
Public Class MyMath
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer) As Integer
        Return num1 + num2
    End Function 'Add
End Class 'Math

설명

일반적으로 XML 웹 서비스에 대한 고유한 프록시 클래스를 BeginInvoke 빌드하지 않는 한 메서드를 직접 호출하지 않습니다.

서비스 설명에서 웹 서비스 설명 언어 도구(Wsdl.exe)에서 생성된 프록시 클래스는 XML 웹 서비스 메서드를 프록시 클래스에서 파생된 이름으로 노출하여 XML 웹 서비스 메서드를 동기적으로 호출합니다. XML 웹 서비스 메서드를 비동기적으로 호출하려면 각 XML 웹 서비스 메서드에 대한 프록시 클래스에 두 개의 추가 메서드가 추가됩니다. 하나는 Begin XML 웹 서비스 메서드의 이름에 접두사로 추가되고 다른 하나는 End 접두사로 추가됩니다.

프록시 클래스는 메서드를 BeginInvoke 호출하여 XML 웹 서비스 메서드에 대한 비동기 호출 호출을 시작합니다. 예를 들어 XML 웹 서비스가 XML 웹 서비스 메서드를 Add노출하는 경우 프록시 클래스에는 XML 웹 서비스 메서드에 대한 호출을 시작하기 위해 명명 BeginAdd된 메서드가 포함됩니다. 코드 BeginAdd내에서 메서드를 호출 BeginInvoke 하고 결과는 예상 반환 형식 Add에 배치됩니다.

메서드 methodName 에 추가되었을 수 있는 사용자 지정 특성(예: SoapDocumentMethodAttribute.)을 찾는 데 사용됩니다. SoapDocumentMethodAttribute 는 SOAP 프로토콜에 필요한 파생 메서드에 대한 추가 정보를 제공합니다.

asyncState 가 전달되고 callback 메서드에서 IAsyncResult 반환되는 내용에 BeginInvoke 포함됩니다. 매개 변수는 asyncState 매개 변수에 지정된 비동기 호출의 컨텍스트에 callback 대한 정보를 결과를 처리하는 대리자로 전달하는 데 사용할 수 있습니다.

적용 대상

추가 정보