SoapExtension.GetInitializer メソッド

定義

派生クラスでオーバーライドされると、SOAP 拡張機能は XML Web サービス メソッドに固有のデータを 1 回の動作で初期化します。

オーバーロード

GetInitializer(Type)

派生クラスでオーバーライドされると、SOAP 拡張機能は XML Web サービスを実装しているクラスに固有のデータを 1 回の動作で初期化します。

GetInitializer(LogicalMethodInfo, SoapExtensionAttribute)

派生クラスでオーバーライドされると、SOAP 拡張機能は XML Web サービス メソッドに適用された属性を使用して、XML Web サービス メソッドに固有のデータを 1 回の動作で初期化します。

GetInitializer(Type)

派生クラスでオーバーライドされると、SOAP 拡張機能は XML Web サービスを実装しているクラスに固有のデータを 1 回の動作で初期化します。

public:
 abstract System::Object ^ GetInitializer(Type ^ serviceType);
public abstract object GetInitializer (Type serviceType);
abstract member GetInitializer : Type -> obj
Public MustOverride Function GetInitializer (serviceType As Type) As Object

パラメーター

serviceType
Type

SOAP 拡張機能の適用対象である XML Web サービスを実装しているクラスの型。

戻り値

SOAP 拡張機能でキャッシングのために初期化する Object

次のコードは、XML Web サービスごとに SOAP 拡張機能固有のデータを保存する方法を示しています。 SOAP 拡張機能が属性ではなく構成ファイルを使用して構成されている場合、SOAP 拡張機能は、SOAP 拡張機能が適用される各クラスのデータを格納できます。 次の使用例は、XML Web サービスを実装するクラスの名前に基づいて、XML Web サービス メソッドとの間で送受信される SOAP メッセージをログに記録するファイルの名前をキャッシュに保存します。 このコード例は、クラスの概要に記載されている TraceExtension SOAP 拡張機能の完全なコード例の SoapExtension 一部です。

   // The extension was configured to run using a configuration file instead of an attribute applied to a 
   // specific XML Web service method. Return a file name based on the class implementing the XML Web service's type.
public:
   virtual Object^ GetInitializer( Type^ WebServiceType ) override
   {
      // Return a file name to log the trace information to based on the passed in type.
      return String::Format( "C:\\{0}.log", WebServiceType->FullName );
   }
// The extension was configured to run using a configuration file instead of an attribute applied to a
// specific XML Web service method. Return a file name based on the class implementing the XML Web service's type.
public override object GetInitializer(Type WebServiceType)
{
   // Return a file name to log the trace information to based on the passed in type.
   return "C:\\" + WebServiceType.FullName + ".log";
}
' The extension was configured to run using a configuration file instead of an attribute applied to a 
' specific XML Web service method.  Return a file name based on the class implementing the XML Web service's type.
Public Overloads Overrides Function GetInitializer(WebServiceType As Type) As Object
   ' Return a file name to log the trace information to based on the passed in type.
    Return "C:\" + WebServiceType.FullName + ".log"
End Function

注釈

ASP.NET によって呼び出される の GetInitializer オーバーロードは、SOAP 拡張機能の指定方法によって異なります。 SOAP 拡張機能を指定するには、次の 2 つの方法があります。

  • から SoapExtensionAttribute派生したカスタム属性を個々の XML Web サービス メソッドに適用します。

  • web.configまたはapp.config構成ファイルに参照を追加します。

いずれかの構成ファイルへの参照を追加すると、SOAP 拡張機能は、その構成ファイルのスコープ内のすべての XML Web サービスに対して実行されます。 構成ファイルを参照して SOAP 拡張機能を指定する場合、ASP.NET は を渡すオーバーロードをType呼び出GetInitializerします。 カスタム属性を適用して拡張機能を指定する場合、ASP.NET は と SoapExtensionAttributeを渡LogicalMethodInfoす をGetInitializer呼び出します。

構成ファイルへの SOAP 拡張機能の追加の詳細については、「 ASP.NET を使用して作成された XML Web サービスの構成オプション」を参照してください。

適用対象

GetInitializer(LogicalMethodInfo, SoapExtensionAttribute)

派生クラスでオーバーライドされると、SOAP 拡張機能は XML Web サービス メソッドに適用された属性を使用して、XML Web サービス メソッドに固有のデータを 1 回の動作で初期化します。

public:
 abstract System::Object ^ GetInitializer(System::Web::Services::Protocols::LogicalMethodInfo ^ methodInfo, System::Web::Services::Protocols::SoapExtensionAttribute ^ attribute);
public abstract object GetInitializer (System.Web.Services.Protocols.LogicalMethodInfo methodInfo, System.Web.Services.Protocols.SoapExtensionAttribute attribute);
abstract member GetInitializer : System.Web.Services.Protocols.LogicalMethodInfo * System.Web.Services.Protocols.SoapExtensionAttribute -> obj
Public MustOverride Function GetInitializer (methodInfo As LogicalMethodInfo, attribute As SoapExtensionAttribute) As Object

パラメーター

methodInfo
LogicalMethodInfo

SOAP 拡張機能が適用される XML Web サービス メソッドの固有の関数プロトタイプを表す LogicalMethodInfo

attribute
SoapExtensionAttribute

XML Web サービス メソッドに適用される SoapExtensionAttribute

戻り値

SOAP 拡張機能でキャッシングのために初期化する Object

次のコードは、 から SoapExtensionAttribute派生したクラスを使用して渡された SOAP 拡張機能固有のデータを取得し、そのデータを に GetInitializerキャッシュする方法を示しています。 このコード例は、クラスの概要に記載されている SOAP 拡張機能の TraceExtension 完全なコード例の SoapExtension 一部です。 このコード例では、 TraceExtensionAttribute が パラメーターに attribute 渡されることに依存しています。 完全なコード例では、 TraceExtensionAttribute から SoapExtensionAttribute 派生し、 プロパティを Filename 追加します。これは、キャッシュに格納されるプロパティです GetInitializer

public:
   // When the SOAP extension is accessed for the first time, cache the 
   // file name passed in by the SoapExtensionAttribute.    
   virtual Object^ GetInitializer( LogicalMethodInfo^ /*methodInfo*/, SoapExtensionAttribute^ attribute ) override
   {
      return (dynamic_cast<TraceExtensionAttribute^>(attribute))->Filename;
   }
// When the SOAP extension is accessed for the first time, cache the
// file name passed in by the SoapExtensionAttribute.
public override object GetInitializer(LogicalMethodInfo methodInfo,
    SoapExtensionAttribute attribute)
{
    return ((TraceExtensionAttribute) attribute).Filename;
}
' When the SOAP extension is accessed for the first time, 
' cache the file name passed in by the SoapExtensionAttribute.

Public Overloads Overrides Function GetInitializer( _
    methodInfo As LogicalMethodInfo, _
    attribute As SoapExtensionAttribute) As Object    
    Return CType(attribute, TraceExtensionAttribute).Filename
End Function

注釈

SOAP 拡張機能が構成ファイルを使用して構成されている場合は、 を GetInitializer 受け入れる Typeオーバーロードが表示されます。

SOAP 拡張機能には、データを初期化する 3 つの機会があり、これらはすべて異なる目的を持ちます。

  • クラス コンストラクター - クラス コンストラクターは、SOAP 拡張機能がインスタンス化されるたびに呼び出され、通常はメンバー変数を初期化するために使用されます。

  • GetInitializer - GetInitializerただし、 は、XML Web サービス メソッドに対して初めて SOAP 要求が行われると、1 回だけ呼び出されます。 カスタム属性が XML Web サービス メソッドに適用されている場合、 GetInitializer メソッドが呼び出されます。 これにより、SOAP 拡張機能は、プロトタイプ情報の XML Web サービス メソッドの を問い合 LogicalMethodInfo わせたり、 から SoapExtensionAttribute派生したクラスによって渡される拡張機能固有のデータにアクセスしたりできます。 戻り値は、ASP.NET によってキャッシュされ、後続 Initialize のメソッドに渡されます。 したがって、 で GetInitializer 実行される初期化は、基本的に 1 回限りのパフォーマンス ヒットにカプセル化されます。

  • Initialize - Initializeは、XML Web サービス メソッドに対して SOAP 要求が行われるたびに呼び出されますが、 でGetInitializer初期化された が渡されるという点Objectで、クラス コンストラクターよりも利点があります。

こちらもご覧ください

適用対象