Share via


방법: 웹 서비스 클라이언트에서 비동기 호출 수행

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

다음 코드 예제에서는 클라이언트 응용 프로그램에서 웹 서비스에 대한 비동기 호출을 만드는 방법을 보여 줍니다. 이 예제에서는 Design Guidelines for XML Web Services Created Using ASP.NET 항목에서 설명하는 지침 중 하나를 보여 줍니다.

fwb442hw.security(ko-kr,VS.100).gif 보안 참고:
이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하십시오.

예제

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<html>
   <script language="C#" runat="server">
      void EnterBtn_Click(Object Src, EventArgs E) 
      {
         MyMath.Math math = new MyMath.Math();
         // Call to Add Web service method asynchronously 
         // and then wait for it to complete.
         IAsyncResult result =
                         math.BeginAdd(Convert.ToInt32(Num1.Text),
                                       Convert.ToInt32(Num2.Text),
                                       null,
                                       null);
         // Wait for asynchronous call to complete.
         result.AsyncWaitHandle.WaitOne();
         // Complete the asynchronous call to Add Web service method.
         float total = math.EndAdd(result);
         // Display results in a Label control.
         Total.Text = "Total: " + total.ToString();
      }
   </script>
<body>
   <form action="MathClient.aspx" runat=server>
      <font face="Verdana"> 
         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 id="Total_Button"
              text="Total" 
              OnClick="EnterBtn_Click" 
              runat=server/>
         <p>
         <asp:label id="Total" runat=server/>
      </font>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
<html>
   <script language="VB" runat="server">
      Sub EnterBtn_Click(Src As Object, E As EventArgs) 
         Dim math As New MyMath.Math()
         ' Call to Add Web service method asynchronously 
         ' and then wait for it to complete.
         Dim result As IAsyncResult = _
                         math.BeginAdd(Convert.ToInt32(Num1.Text), _
                                       Convert.ToInt32(Num2.Text), _
                                       Nothing, _
                                       Nothing)
               
         ' Wait for asynchronous call to complete.
         result.AsyncWaitHandle.WaitOne()
         ' Complete the asynchronous call to Add Web service method.
         Dim addtotal As Single = math.EndAdd(result)
         ' Display results in a Label control.
         Total.Text = "Total: " & addtotal.ToString()
      End Sub
   </script>
<body>
   <form action="MathClient.aspx" runat=server>
      <font face="Verdana"> 
         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 id="Total_Button"
              text="Total" 
              OnClick="EnterBtn_Click" 
              runat=server/>
         <p>
         <asp:label id="Total" runat=server/>
      </font>
    </form>
</body>
</html>

참고 항목

작업

방법: 대기 기술을 사용하여 비동기 웹 서비스 클라이언트 구현
방법: 콜백 기술을 사용하여 비동기 웹 서비스 클라이언트 구현

개념

ASP.NET을 사용하여 만든 XML Web services에 대한 디자인 지침
XML Web services와 비동기적으로 통신