ServiceDescriptionImporter 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
XML 웹 서비스에 대한 클라이언트 프록시 클래스를 생성하는 방법을 노출합니다.
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.asmx 노출되는 ASP.NET 사용하여 웹 서비스에 대한 WSDL 설명을 가져오려면 http://localhost/service.asmx?WSDL 이동하면 됩니다.
클래스 ServiceDescriptionImporter 를 사용하면 WSDL 설명에 포함된 정보를 개체로 쉽게 가져올 수 있습니다 System.CodeDom.CodeCompileUnit . 매개 변수 값을 Style 조정하여 인스턴스에 웹 서비스를 투명하게 호출하여 웹 서비스의 기능을 제공하는 클라이언트 프록시 클래스를 생성하거나 구현하지 않고 웹 서비스의 기능을 캡슐화하는 추상 클래스를 생성하도록 지시 ServiceDescriptionImporter 할 수 있습니다.
그런 다음 결과 CodeCompileUnit 개체의 코드를 직접 호출하거나 원하는 언어로 내보낼 수 있습니다.
Important
신뢰할 수 없는 입력에는 사용하지 ServiceDescriptionImporter 마세요. 신뢰할 수 없는 원본에서 ServiceDescription 가져오면 임의의 URL에 액세스하거나 임의의 .NET 형식을 인스턴스화하는 코드 생성이 발생하여 잠재적으로 보안 취약성이 발생할 수 있습니다.
생성자
| Name | Description |
|---|---|
| ServiceDescriptionImporter() |
ServiceDescriptionImporter 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| CodeGenerationOptions |
코드 생성을 위한 다양한 옵션을 가져오거나 설정합니다. |
| CodeGenerator |
서비스 설명 가져오기에서 사용하는 코드 생성기를 가져오거나 설정합니다. |
| ProtocolName |
설명된 XML 웹 서비스에 액세스하는 데 사용되는 프로토콜을 가져오거나 설정합니다. |
| Schemas |
속성에서 XmlSchemas 사용되는 값을 ServiceDescriptions 가져옵니다. |
| ServiceDescriptions |
가져올 인스턴스의 ServiceDescription 컬렉션을 가져옵니다. |
| Style |
값을 가져올 때 ServiceDescriptions 생성되는 코드 스타일(클라이언트 또는 서버)을 결정하는 값을 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| 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) |