ServiceDescriptionImporter クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
XML Web サービスのクライアント プロキシ クラスを生成する手段を公開します。
public ref class ServiceDescriptionImporter
public class ServiceDescriptionImporter
type ServiceDescriptionImporter = class
Public Class ServiceDescriptionImporter
- 継承
-
ServiceDescriptionImporter
例
次の例は、WSDL ファイルによって記述された XML Web サービスを呼び出すプロキシ クライアント コードを生成するために、 ServiceDescriptionImporter クラスを使用する方法を示しています。
#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 Web サービスへのインターフェイスは、通常、Web サービス記述言語 (WSDL) ファイルによって記述されます。 たとえば、http://localhost/service.asmx で公開されている ASP.NET を使用して Web サービスの WSDL 記述を取得するには、単に http://localhost/service.asmx?WSDL に移動します。
ServiceDescriptionImporter クラスを使用すると、WSDL 記述に含まれる情報をSystem.CodeDom.CodeCompileUnit オブジェクトに簡単にインポートできます。 Style パラメーターの値を調整することで、ServiceDescriptionImporter インスタンスに対して、透過的に呼び出して Web サービスの機能を提供するクライアント プロキシ クラスを生成するか、実装せずに Web サービスの機能をカプセル化する抽象クラスを生成するように指示できます。
結果の CodeCompileUnit オブジェクト内のコードは、直接呼び出すか、選択した言語でエクスポートできます。
Important
信頼されていない入力で ServiceDescriptionImporter を使用しないでください。 信頼されていないソースから ServiceDescription をインポートすると、任意の URL にアクセスしたり、任意の.NET型をインスタンス化したりするコード生成が発生し、セキュリティの脆弱性につながる可能性があります。
コンストラクター
| 名前 | 説明 |
|---|---|
| ServiceDescriptionImporter() |
ServiceDescriptionImporter クラスの新しいインスタンスを初期化します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| CodeGenerationOptions |
コード生成のさまざまなオプションを取得または設定します。 |
| CodeGenerator |
サービス記述インポーターによって使用されるコード ジェネレーターを取得または設定します。 |
| ProtocolName |
記述された XML Web サービスへのアクセスに使用するプロトコルを取得または設定します。 |
| Schemas |
XmlSchemas プロパティによって使用されるServiceDescriptionsを取得します。 |
| ServiceDescriptions |
インポートする ServiceDescription インスタンスのコレクションを取得します。 |
| Style |
ServiceDescriptions値のインポート時に生成されるコード (クライアントまたはサーバー) のスタイルを決定する値を取得または設定します。 |
メソッド
| 名前 | 説明 |
|---|---|
| AddServiceDescription(ServiceDescription, String, String) |
指定した ServiceDescription をインポートする ServiceDescriptions 値のコレクションに追加します。 |
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GenerateWebReferences(WebReferenceCollection, CodeDomProvider, CodeCompileUnit, WebReferenceOptions) |
Web 参照のコレクションをコンパイルして、クライアント プロキシまたはサーバー スタブを生成します。 |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| Import(CodeNamespace, CodeCompileUnit) |
ServiceDescriptions プロパティで指定されたコードを生成する、指定したStyle値をインポートします。 |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |