ServiceDescriptionImporter 클래스

정의

XML Web services의 클라이언트 프록시 클래스를 생성하는 방법을 노출합니다.

public ref class ServiceDescriptionImporter
public class ServiceDescriptionImporter
type ServiceDescriptionImporter = class
Public Class ServiceDescriptionImporter
상속
ServiceDescriptionImporter

예제

다음 예제에서는 클래스를 ServiceDescriptionImporter 사용하여 WSDL 파일에서 설명하는 XML 웹 서비스를 호출하는 프록시 클라이언트 코드를 생성하는 방법을 보여 줍니다.

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

using namespace System;
using namespace System::Web::Services::Description;
using namespace System::CodeDom;
using namespace System::CodeDom::Compiler;

int main()
{
   // Get a WSDL file describing a service.
   ServiceDescription^ description = ServiceDescription::Read( "service.wsdl" );

   // Initialize a service description importer.
   ServiceDescriptionImporter^ importer = gcnew ServiceDescriptionImporter;
   importer->ProtocolName = "Soap12"; // Use SOAP 1.2.
   importer->AddServiceDescription( description, nullptr, nullptr );

   // Report on the service descriptions.
   Console::WriteLine( "Importing {0} service descriptions with {1} associated schemas.", importer->ServiceDescriptions->Count, importer->Schemas->Count );

   // Generate a proxy client.
   importer->Style = ServiceDescriptionImportStyle::Client;

   // Generate properties to represent primitive values.
   importer->CodeGenerationOptions = System::Xml::Serialization::CodeGenerationOptions::GenerateProperties;

   // Initialize a Code-DOM tree into which we will import the service.
   CodeNamespace^ nmspace = gcnew CodeNamespace;
   CodeCompileUnit^ unit = gcnew CodeCompileUnit;
   unit->Namespaces->Add( nmspace );
   
   // Import the service into the Code-DOM tree. This creates proxy code
   // that uses the service.
   ServiceDescriptionImportWarnings warning = importer->Import(nmspace,unit);
   if ( warning == (ServiceDescriptionImportWarnings)0 )
   {
      // Generate and print the proxy code in C#.
      CodeDomProvider^ provider = CodeDomProvider::CreateProvider( "CSharp" );
      ICodeGenerator^ generator = provider->CreateGenerator();
      generator->GenerateCodeFromCompileUnit( unit, Console::Out, gcnew CodeGeneratorOptions );
   }
   else
   {
      // Print an error message.
      Console::WriteLine( warning );
   }
}
using System;
using System.Web.Services.Description;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Security.Permissions;

public class Import {

    public static void Main() 
    {
        Run();
    }

    [PermissionSetAttribute(SecurityAction.Demand, Name = "Full Trust")]
    public static void Run()
    {
    // Get a WSDL file describing a service.
    ServiceDescription description = ServiceDescription.Read("service.wsdl");

    // Initialize a service description importer.
    ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
    importer.ProtocolName = "Soap12";  // Use SOAP 1.2.
    importer.AddServiceDescription(description,null,null);

    // Report on the service descriptions.
    Console.WriteLine("Importing {0} service descriptions with {1} associated schemas.",
                      importer.ServiceDescriptions.Count, importer.Schemas.Count);

    // Generate a proxy client.
    importer.Style = ServiceDescriptionImportStyle.Client;

    // Generate properties to represent primitive values.
    importer.CodeGenerationOptions = System.Xml.Serialization.CodeGenerationOptions.GenerateProperties;

    // Initialize a Code-DOM tree into which we will import the service.
    CodeNamespace nmspace = new CodeNamespace();
    CodeCompileUnit unit = new CodeCompileUnit();
    unit.Namespaces.Add(nmspace);

    // Import the service into the Code-DOM tree. This creates proxy code
    // that uses the service.
    ServiceDescriptionImportWarnings warning = importer.Import(nmspace,unit);

    if (warning == 0)
    {
        // Generate and print the proxy code in C#.
        CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
        provider.GenerateCodeFromCompileUnit(unit, Console.Out, new CodeGeneratorOptions() );
    }
    else
    {
        // Print an error message.
        Console.WriteLine(warning); 
    }
}
}

설명

XML 웹 서비스에 대한 인터페이스는 일반적으로 WSDL(웹 서비스 설명 언어) 파일로 설명됩니다. 예를 들어 노출된 http://localhost/service.asmxASP.NET 사용하여 웹 서비스에 대한 WSDL 설명을 가져오려면 간단히 이동합니다http://localhost/service.asmx?WSDL.

ServiceDescriptionImporter 클래스를 사용하면 WSDL 설명에 포함된 정보를 개체로 쉽게 가져올 수 있습니다 System.CodeDom.CodeCompileUnit . 매개 변수 값을 Style 조정하여 인스턴스에 웹 서비스를 투명하게 호출하여 웹 서비스의 기능을 제공하는 클라이언트 프록시 클래스를 생성하거나 구현하지 않고 웹 서비스의 기능을 캡슐화하는 추상 클래스를 생성하도록 지시 ServiceDescriptionImporter 할 수 있습니다.

그런 다음 결과 CodeCompileUnit 개체의 코드를 직접 호출하거나 원하는 언어로 내보낼 수 있습니다.

생성자

ServiceDescriptionImporter()

ServiceDescriptionImporter 클래스의 새 인스턴스를 초기화합니다.

속성

CodeGenerationOptions

다양한 코드 생성 옵션을 가져오거나 설정합니다.

CodeGenerator

서비스 설명 가져오기에서 사용하는 코드 생성기를 가져오거나 설정합니다.

ProtocolName

설명된 XML Web services에 액세스하는 데 사용되는 프로토콜을 가져오거나 설정합니다.

Schemas

XmlSchemas 속성에서 사용한 ServiceDescriptions를 가져옵니다.

ServiceDescriptions

가져올 ServiceDescription 인스턴스의 컬렉션을 가져옵니다.

Style

ServiceDescriptions 값을 가져올 때 생성되는 코드 스타일(클라이언트 또는 서버)을 결정하는 값을 가져오거나 설정합니다.

메서드

AddServiceDescription(ServiceDescription, String, String)

가져올 ServiceDescription 값의 컬렉션에 지정된 ServiceDescriptions을 추가합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GenerateWebReferences(WebReferenceCollection, CodeDomProvider, CodeCompileUnit, WebReferenceOptions)

웹 참조 컬렉션을 컴파일하여 클라이언트 프록시 또는 서버 스텁을 생성합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Import(CodeNamespace, CodeCompileUnit)

지정한 ServiceDescriptions 값을 가져오고 Style 속성이 지정하는 코드를 생성합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상