다음을 통해 공유


방법: 콘솔 응용 프로그램 클라이언트 만들기

코드 예제

웹 서비스 클라이언트 역할을 하는 콘솔 응용 프로그램을 만드는 방법은 매우 간단합니다. 프록시 클래스를 만든 다음 이 프록시 클래스를 콘솔 응용 프로그램에서 액세스할 수 있으면 프록시 클래스의 새 인스턴스 만들 수 있습니다. 콘솔 응용 프로그램에서 액세스할 수 있도록 하는 가장 쉬운 방법은 콘솔 응용 프로그램에 대한 어셈블리로 프록시 클래스를 컴파일하는 것입니다. 또는 프록시 클래스를 어셈블리로 컴파일한 다음 콘솔 응용 프로그램이 액세스할 수 있는 위치에 배포해도 됩니다.

웹 서비스 콘솔 클라이언트 응용 프로그램을 만들려면

  1. 웹 서비스에 대한 프록시를 만듭니다.

    Wsdl https://www.contoso.com/Counter.asmx?WSDL
    
    Wsdl /language:VB https://www.contoso.com/Counter.asmx?WSDL
    

    자세한 내용은 XML Web services 프록시 만들기를 참조하십시오.

  2. 콘솔 응용 프로그램을 만듭니다.

  3. 클라이언트 코드에서 프록시 클래스의 인스턴스를 만듭니다.

    Counter myCounter = new Counter();
    
    Dim myCounter As New Counter()
    
  4. 웹 서비스 메서드와 통신하는 프록시 클래스의 메서드를 호출합니다.

    UsageCount = counter.ServiceUsage();
    
    UsageCount = counter.ServiceUsage()
    
  5. 콘솔 응용 프로그램을 실행 파일로 컴파일합니다. 다음 예제에서는 콘솔 응용 프로그램이 UsageMonitor로 저장됩니다.

    csc /t:exe /r:System.Web.dll,System.XML.dll,System.Web.Services.dll UsageMonitor.cs Counter.cs
    
    vbc /t:exe /r:System.dll,System.Web.dll,System.XML.dll,System.Web.Services.dll UsageMonitor.vb Counter.vb
    

예제

 using System;
class UsageMonitor {
   public static void Main(string[] args) {
     int UsageCount;
     // Create an instance of the Web service class.
     Counter myCounter = new Counter();
     // Call the Web service method ServiceUsage.
     UsageCount = myCounter.ServiceUsage();
     // Output the results to the console.
     if (UsageCount == 1)
       Console.WriteLine("Web service has been utilized >" + UsageCount.ToString() + "< time.");
     else      
       Console.WriteLine("Web service has been utilized >" + UsageCount.ToString() + "< times.");
  }  
}
Imports System
Class UsageMonitor
    Public Shared Sub Main()
        Dim UsageCount As Integer
        ' Create an instance of the Web service class.
        Dim myCounter As New Counter()
        ' Call the Web service method ServiceUsage.
        UsageCount = myCounter.ServiceUsage()
        ' Output the results to the console.
        If UsageCount = 1 Then
            Console.WriteLine("Web service has been utilized >" _
               & UsageCount.ToString() & "< time.")
        Else
            Console.WriteLine("Web service has been utilized >" _
               & UsageCount.ToString() & "< times.")
        End If
    End Sub
End Class

참고 항목

개념

XML Web services 클라이언트 빌드

기타 리소스

XML Web services에 대한 클라이언트 만들기

Footer image

Copyright © 2007 by Microsoft Corporation. All rights reserved.