ServiceDescriptionImporter クラス
アセンブリ: System.Web.Services (system.web.services.dll 内)


XML Web サービスへのインターフェイスは、通常 Web サービス記述言語 (WSDL: Web Services Description Language) ファイルで記述されます。たとえば、http://localhost/service.asmx で公開されている ASP.NET を使用した Web サービスの WSDL の説明を取得するには、単に http://localhost/service.asmx?WSDL に移動します。
ServiceDescriptionImporter クラスを使用すると、WSDL の説明に含まれている情報を簡単に System.CodeDom.CodeCompileUnit オブジェクトにインポートできます。Style パラメータの値を調整することによって、ServiceDescriptionImporter インスタンスに対して、Web サービスの機能を透過的に呼び出すことによって提供するクライアント プロキシ クラスを生成するか、Web サービスの機能を実装せずにカプセル化する抽象クラスを生成するかを指示できます。
結果の CodeCompileUnit オブジェクト内のコードは、直接呼び出すことも、指定した言語でエクスポートすることもできます。

ServiceDescriptionImporter クラスを使用して WSDL ファイルで記述されている XML Web サービスを呼び出すプロキシ クライアント コードを生成する例を次に示します。
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); } } }
#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 ); } }

System.Web.Services.Description.ServiceDescriptionImporter


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ServiceDescriptionImporter クラスのページへのリンク