HttpSimpleClientProtocol.BeginInvoke 메서드

정의

XML 웹 서비스의 메서드에 대한 비동기 호출을 시작합니다.

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

매개 변수

methodName
String

XML 웹 서비스 메서드의 이름입니다.

requestUrl
String

를 만들 때 사용할 URL입니다 WebRequest.

parameters
Object[]

XML 웹 서비스 메서드에 전달할 매개 변수를 포함하는 개체의 배열입니다. 배열의 값 순서는 파생 클래스의 호출 메서드에 있는 매개 변수의 순서에 해당합니다.

callback
AsyncCallback

비동기 메서드 호출이 완료된 경우 호출할 대리자입니다. null이 경우 callback 대리자가 호출되지 않습니다.

asyncState
Object

클라이언트에서 제공하는 추가 정보입니다.

반품

IAsyncResult XML 웹 서비스 메서드에서 반환 값을 가져오기 위해 메서드에 전달할 EndInvoke(IAsyncResult) 수 있는 값입니다.

예외

요청이 서버 컴퓨터에 도달했지만 성공적으로 처리되지 않았습니다.

예제

다음 코드 예제는 Math XML 웹 서비스를 호출하는 ASP.NET Web Form입니다. 함수 내에서 EnterBtn_Click 웹 양식은 XML 웹 서비스 메서드의 비동기 호출을 Add 시작하고 완료합니다.

<%@ Page Language="VB" %>
<html>
    <script language="VB" runat="server">
    Sub EnterBtn_Click(Src As Object, E As EventArgs)
        Dim math As New MyMath.Math()
        
        ' Call to Add XML Web service method asynchronously.
        Dim result As IAsyncResult = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), Nothing, Nothing)
        
        ' Wait for the asynchronous call to complete.
        result.AsyncWaitHandle.WaitOne()
        
        ' Complete the asynchronous call to the Add XML Web service method.
        Dim iTotal As Integer = math.EndAdd(result)
        
        Total.Text = "Total: " & iTotal.ToString()
    End Sub 'EnterBtn_Click
 
  </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>

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

namespace MyMath
{
   [XmlRootAttribute("snippet1>",Namespace="http://MyMath/",IsNullable=false)]
   public ref class Math: public HttpGetClientProtocol
   {
   public:
      Math()
      {
         this->Url = "http://www.contoso.com/math.asmx";
      }

      [HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,
      System::Web::Services::Protocols::UrlParameterWriter::typeid)]
      int Add( String^ num1, String^ num2 )
      {
         array<Object^>^temp0 = {num1,num2};
         return  *dynamic_cast<int^>(this->Invoke( "Add", String::Concat( this->Url, "/Add" ), temp0 ));
      }

      IAsyncResult^ BeginAdd( String^ num1, String^ num2, AsyncCallback^ callback, Object^ asyncState )
      {
         array<Object^>^temp1 = {num1,num2};
         return this->BeginInvoke( "Add", String::Concat( this->Url, "/Add" ), temp1, callback, asyncState );
      }

      int EndAdd( IAsyncResult^ asyncResult )
      {
         return  *dynamic_cast<int^>(this->EndInvoke( asyncResult ));
      }
   };
}
namespace MyMath
{
    [XmlRootAttribute("int", Namespace = "http://MyMath/", IsNullable = false)]
    public class Math : HttpGetClientProtocol
    {
        public Math()
        {
            this.Url = "http://www.contoso.com/math.asmx";
        }

        [HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader),
            typeof(System.Web.Services.Protocols.UrlParameterWriter))]
        public int Add(int num1, int num2)
        {
            return ((int)(this.Invoke("Add", ((this.Url) + ("/Add")),
                new object[] { num1, num2 })));
        }

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

        public int EndAdd(IAsyncResult asyncResult)
        {
            return ((int)(this.EndInvoke(asyncResult)));
        }
    }
}
Namespace MyMath
    <XmlRootAttribute("int", Namespace := "http://MyMath/", IsNullable := False)> _
    Public Class Math
        Inherits HttpGetClientProtocol
        
        Public Sub New()
            Me.Url = "http://www.contoso.com/math.asmx"
        End Sub
        
        <HttpMethodAttribute(GetType(XmlReturnReader), GetType(UrlParameterWriter))> _
        Public Function Add(num1 As String, num2 As String) As Integer
            Return CInt(Me.Invoke("Add", Me.Url + "/Add", New Object() {num1, num2}))
        End Function 'Add
        
        
        Public Function BeginAdd(num1 As String, num2 As String, callback As AsyncCallback, asyncState As Object) As IAsyncResult
            Return Me.BeginInvoke("Add", Me.Url + "/Add", New Object() {num1, num2}, callback, asyncState)
        End Function 'BeginAdd
        
        
        Public Function EndAdd(asyncResult As IAsyncResult) As Integer
            Return CInt(Me.EndInvoke(asyncResult))
        End Function 'EndAdd
    End Class
End Namespace 'MyMath

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

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

Public Class Math
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer) As Integer
        Return num1 + num2
    End Function 'Add
End Class 'Math

설명

methodName 매개 변수는 매개 변수의 형식을 찾고 메서드를 호출하는 메서드의 값을 반환하는 BeginInvoke 데 사용됩니다. 메서드에 추가되었을 수 있는 사용자 지정 특성을 찾는 데도 사용됩니다. SoapDocumentMethodAttribute, SoapRpcMethodAttributeHTTP XmlElementAttribute 프로토콜에 필요한 파생 메서드에 대한 추가 정보를 제공합니다.

asyncState 가 전달되고 callback 메서드에서 IAsyncResult 반환되는 값에 BeginInvoke 포함됩니다. 비동기 호출의 컨텍스트에서 비동기 결과의 callback처리로 정보를 전달하는 데 유용합니다.

적용 대상

추가 정보