次の方法で共有


SoapExtension.GetInitializer メソッド (Type)

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

Overloads Public MustOverride Function GetInitializer( _
   ByVal serviceType As Type _) As Object
[C#]
public abstract object GetInitializer(TypeserviceType);
[C++]
public: virtual Object* GetInitializer(Type* serviceType) = 0;
[JScript]
public abstract function GetInitializer(
   serviceType : Type) : Object;

パラメータ

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

戻り値

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

解説

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

  • SoapExtensionAttribute から派生したカスタム属性をそれぞれの XML Web サービス メソッドに適用する方法。
  • web.config 構成ファイルまたは app.config 構成ファイルに参照を追加する方法。

構成ファイルの 1 つに参照を追加すると、SOAP 拡張機能はその構成ファイルのスコープ内のすべての XML Web サービスを対象に実行します。構成ファイルを参照するように SOAP 拡張機能を指定すると、 Type を渡す GetInitializer オーバーロードを ASP.NET が呼び出します。カスタム属性を適用するように拡張機能を指定すると、 LogicalMethodInfoSoapExtensionAttribute を渡す GetInitializer を ASP.NET が呼び出します。

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

使用例

[Visual Basic, C#, C++] SOAP 拡張機能の固有データを XML Web サービス単位で保存するコード例を次に示します。属性ではなく構成ファイルを使用して SOAP 拡張機能を構成している場合、SOAP 拡張機能は SOAP 拡張機能の適用対象であるそれぞれのクラスのデータを格納できます。この例では XML Web サービスを実装しているクラスの名前に基づき、XML Web サービス メソッドとの間で送受信された SOAP メッセージのログをとるファイルの名前をキャッシュに保存します。このコード例は、 SoapExtension クラスの概要にある TraceExtension SOAP 拡張機能のフルコード例の一部です。

 
' 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

[C#] 
// 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";    
}

[C++] 
// 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:
Object* GetInitializer(Type* WebServiceType) 
{
   // Return a file name to log the trace information to based on the passed in type.
   return String::Format( S"C:\\{0}.log", WebServiceType->FullName );    
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

SoapExtension クラス | SoapExtension メンバ | System.Web.Services.Protocols 名前空間 | SoapExtension.GetInitializer オーバーロードの一覧