This documentation is archived and is not being maintained.

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.

Namespace:  System.Web.Services.Protocols
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.

Return Value

Type: System::Object
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 (dynamic_cast<TraceExtensionAttribute*> (attribute))->Filename;
   }

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Show: