SoapExtension::GetInitializer Method (LogicalMethodInfo, SoapExtensionAttribute)
When overridden in a derived class, allows a SOAP extension to initialize data specific to an XML Web service method using an attribute applied to the XML Web service method at a one time performance cost.
Assembly: System.Web.Services (in System.Web.Services.dll)
public: virtual Object^ GetInitializer( LogicalMethodInfo^ methodInfo, SoapExtensionAttribute^ attribute ) abstract
Parameters
- methodInfo
- Type: System.Web.Services.Protocols::LogicalMethodInfo
A LogicalMethodInfo representing the specific function prototype for the XML Web service method to which the SOAP extension is applied.
- attribute
- Type: System.Web.Services.Protocols::SoapExtensionAttribute
The SoapExtensionAttribute applied to the XML Web service method.
If the SOAP extension is configured using a configuration file see the GetInitializer overload that accepts a Type.
A SOAP extension has three opportunities to initialize data and they all have different purposes:
Class constructor - The class constructor is called every time a SOAP extension is instantiated and is typically used to initialize member variables.
GetInitializer - GetInitializer, however, is called just once, the first time a SOAP request is made to an XML Web services method. If a custom attribute is applied to the XML Web service method, the GetInitializer method is invoked. This allows the SOAP extension to interrogate the LogicalMethodInfo of an XML Web service method for prototype information or to access extension-specific data passed by a class deriving from SoapExtensionAttribute. The return value is cached by ASP.NET and passed into subsequent Initialize methods. Therefore, initialization done in GetInitializer is encapsulated essentially into a one-time performance hit.
Initialize - Initialize is called every time a SOAP request is made to an XML Web service method, but has an advantage over the class constructor, in that the Object initialized in GetInitializer is passed to it.
The following code demonstrates how you can obtain SOAP extension-specific data passed in using a class that derives from SoapExtensionAttribute, and then cache that data in GetInitializer. This code example is part of a full code example for a TraceExtension SOAP extension that can be found in the SoapExtension class overview. This code example relies on a TraceExtensionAttribute being passed into the attribute parameter. In the full code example, TraceExtensionAttribute derives from SoapExtensionAttribute and adds a Filename property, which is what GetInitializer stores in the cache.
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; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.