SoapExtension.GetInitializer Method (LogicalMethodInfo, SoapExtensionAttribute)
Assembly: System.Web.Services (in system.web.services.dll)
public: virtual Object^ GetInitializer ( LogicalMethodInfo^ methodInfo, SoapExtensionAttribute^ attribute ) abstract
public abstract Object GetInitializer ( LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute )
public abstract function GetInitializer ( methodInfo : LogicalMethodInfo, attribute : SoapExtensionAttribute ) : Object
Not applicable.
Parameters
- methodInfo
A LogicalMethodInfo representing the specific function prototype for the XML Web service method to which the SOAP extension is applied.
- attribute
The SoapExtensionAttribute applied to the XML Web service method.
Return Value
The Object that the SOAP extension initializes for caching.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; }
// When the SOAP extension is accessed for the first time, cache the
// file name passed in by the SoapExtensionAttribute.
public Object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return ((TraceExtensionAttribute)(attribute)).get_Filename();
} //GetInitializer
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.