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 コンストラクタ
アセンブリ: System.Web.Services (system.web.services.dll 内)


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

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 プロパティ

名前 | 説明 | |
---|---|---|
![]() | CodeGenerationOptions | コード生成のさまざまなオプションを取得または設定します。 |
![]() | CodeGenerator | サービスの説明インポータによって使用されるコード ジェネレータを取得または設定します。 |
![]() | ProtocolName | 記述されている XML Web サービスにアクセスするために使用されるプロトコルを取得または設定します。 |
![]() | Schemas | ServiceDescriptions プロパティによって使用される XmlSchemas を取得します。 |
![]() | ServiceDescriptions | インポートされる ServiceDescription インスタンスのコレクションを取得します。 |
![]() | Style | ServiceDescriptions 値がインポートされるときに生成されるコードのスタイル (クライアントまたはサーバー) を決定する値を取得または設定します。 |

ServiceDescriptionImporter メソッド

名前 | 説明 | |
---|---|---|
![]() | AddServiceDescription | 指定した ServiceDescription を、インポートされる ServiceDescriptions 値のコレクションに追加します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GenerateWebReferences | Web 参照のコレクションをコンパイルして、クライアント プロキシまたはサーバー スタブを作成します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | Import | 指定した ServiceDescriptions 値をインポートします。これによって、Style プロパティで指定されたとおりにコードを生成します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

ServiceDescriptionImporter メンバ
XML Web サービスのためのクライアント プロキシ クラスの生成方法を公開します。
ServiceDescriptionImporter データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | CodeGenerationOptions | コード生成のさまざまなオプションを取得または設定します。 |
![]() | CodeGenerator | サービスの説明インポータによって使用されるコード ジェネレータを取得または設定します。 |
![]() | ProtocolName | 記述されている XML Web サービスにアクセスするために使用されるプロトコルを取得または設定します。 |
![]() | Schemas | ServiceDescriptions プロパティによって使用される XmlSchemas を取得します。 |
![]() | ServiceDescriptions | インポートされる ServiceDescription インスタンスのコレクションを取得します。 |
![]() | Style | ServiceDescriptions 値がインポートされるときに生成されるコードのスタイル (クライアントまたはサーバー) を決定する値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | AddServiceDescription | 指定した ServiceDescription を、インポートされる ServiceDescriptions 値のコレクションに追加します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GenerateWebReferences | Web 参照のコレクションをコンパイルして、クライアント プロキシまたはサーバー スタブを作成します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | Import | 指定した ServiceDescriptions 値をインポートします。これによって、Style プロパティで指定されたとおりにコードを生成します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- ServiceDescriptionImporterのページへのリンク