SoapExtension.GetInitializer Method (Type)

When overridden in a derived class, allows a SOAP extension to initialize data specific to a class implementing an XML Web service at a one time performance cost.

Namespace:  System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)

public abstract Object GetInitializer(
	Type serviceType


Type: System.Type

The type of the class implementing the XML Web service to which the SOAP extension is applied.

Return Value

Type: System.Object
The Object that the SOAP extension initializes for caching.

The overload of GetInitializer that gets called by ASP.NET depends on how the SOAP extension was specified. There are two methods for specifying a SOAP extension:

  • Apply a custom attribute, deriving from SoapExtensionAttribute, to the individual XML Web service method.

  • Add a reference in either the web.config or app.config configuration files.

If you add a reference to one of the configuration files, the SOAP extension runs for all XML Web services within the scope of that configuration file. When specifying, a SOAP extension by referencing a configuration file, ASP.NET invokes the GetInitializer overload that passes in a Type. When specifying an extension by applying a custom attribute, ASP.NET invokes the GetInitializer that passes in a LogicalMethodInfo and a SoapExtensionAttribute.

For details on adding SOAP extensions to a configuration file, see [<topic://cpconconfigurationoptionsforaspnetwebservices>].

The following code demonstrates how one can save SOAP extension specific data on a per XML Web service basis. If the SOAP extension is configured using a configuration file instead of an attribute, the SOAP extension can store data for each class to which the SOAP extension is applied. This example saves the name of a file in which to log the SOAP messages sent to and from the XML Web service method based on the name of the class implementing the XML Web service into the cache. This code example is part of a full code example for a TraceExtension SOAP extension that can be found in the SoapExtension class overview.

    // 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";    

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft