Share via


ServiceDescriptionImporter Sınıf

Tanım

XML Web hizmetleri için istemci proxy sınıfları oluşturmanın bir aracıdır.

public ref class ServiceDescriptionImporter
public class ServiceDescriptionImporter
type ServiceDescriptionImporter = class
Public Class ServiceDescriptionImporter
Devralma
ServiceDescriptionImporter

Örnekler

Aşağıdaki örnekte, bir WSDL dosyası tarafından açıklanan XML Web hizmetini çağıran proxy istemci kodu oluşturmak için sınıfının kullanımı ServiceDescriptionImporter gösterilmektedir.

#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); 
    }
}
}

Açıklamalar

XML Web hizmeti arabirimi genellikle bir Web Hizmetleri Açıklama Dili (WSDL) dosyasıyla açıklanır. Örneğin, konumunda http://localhost/service.asmxkullanıma sunulan ASP.NET kullanarak bir Web hizmetinin WSDL açıklamasını almak için http://localhost/service.asmx?WSDLadresine gitmeniz yeterlidir.

sınıfı, ServiceDescriptionImporter WSDL açıklamasında yer alan bilgileri bir nesneye System.CodeDom.CodeCompileUnit kolayca içeri aktarmanızı sağlar. parametresinin Style değerini ayarlayarak, bir ServiceDescriptionImporter örneğe saydam bir şekilde çağırarak Web hizmetinin işlevselliğini sağlayan bir istemci proxy sınıfı oluşturmasını veya Web hizmetinin işlevselliğini uygulamadan kapsülleyen bir soyut sınıf oluşturmasını sağlayabilirsiniz.

Sonuçta elde edilen CodeCompileUnit nesnedeki kod doğrudan çağrılabilir veya seçtiğiniz dilde dışarı aktarılabilir.

Oluşturucular

ServiceDescriptionImporter()

ServiceDescriptionImporter sınıfının yeni bir örneğini başlatır.

Özellikler

CodeGenerationOptions

Kod oluşturma için çeşitli seçenekleri alır veya ayarlar.

CodeGenerator

Hizmet açıklaması içeri aktarıcısı tarafından kullanılan kod oluşturucuyu alır veya ayarlar.

ProtocolName

Açıklanan XML Web hizmetlerine erişmek için kullanılan protokolü alır veya ayarlar.

Schemas

XmlSchemas özelliği tarafından kullanılan değerini ServiceDescriptions alır.

ServiceDescriptions

İçeri aktarılacak örneklerin ServiceDescription koleksiyonunu alır.

Style

Değerler içeri aktarıldığında ServiceDescriptions oluşturulan kod stilini (istemci veya sunucu) belirleyen bir değeri alır veya ayarlar.

Yöntemler

AddServiceDescription(ServiceDescription, String, String)

Belirtilen ServiceDescription değerini içeri aktarılacak değerler koleksiyonuna ServiceDescriptions ekler.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GenerateWebReferences(WebReferenceCollection, CodeDomProvider, CodeCompileUnit, WebReferenceOptions)

İstemci proxy'si veya sunucu saptaması oluşturmak için bir Web başvuruları koleksiyonu derler.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
Import(CodeNamespace, CodeCompileUnit)

özelliği tarafından Style belirtilen kodu oluşturan belirtilen ServiceDescriptions değerleri içeri aktarır.

MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır