SoapExtension.GetInitializer 方法

定义

当在派生类中重写时,允许 SOAP 扩展以一次执行的成本初始化特定于 XML Web services 方法的数据。When overridden in a derived class, allows a SOAP extension to initialize data specific to an XML Web service method at a one time performance cost.

重载

GetInitializer(Type)

当在派生类中重写时,允许 SOAP 扩展以一次执行的成本初始化特定于实现 XML Web services 的类的数据。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.

GetInitializer(LogicalMethodInfo, SoapExtensionAttribute)

当在派生类中重写时,允许 SOAP 扩展以一次执行的成本使用应用于 XML Web services 方法的特性来初始化特定于 XML Web services 方法的数据。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.

GetInitializer(Type)

当在派生类中重写时,允许 SOAP 扩展以一次执行的成本初始化特定于实现 XML Web services 的类的数据。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.

public:
 abstract System::Object ^ GetInitializer(Type ^ serviceType);
public abstract object GetInitializer (Type serviceType);
abstract member GetInitializer : Type -> obj
Public MustOverride Function GetInitializer (serviceType As Type) As Object

参数

serviceType
Type

实现应用 SOAP 扩展的 XML Web services 的类的类型。The type of the class implementing the XML Web service to which the SOAP extension is applied.

返回

Object,SOAP 扩展将对其进行初始化以用于缓存。The Object that the SOAP extension initializes for caching.

示例

下面的代码演示如何一个可以将 SOAP 扩展特定的数据保存在每个 XML Web 服务的基础。The following code demonstrates how one can save SOAP extension specific data on a per XML Web service basis. 如果使用配置文件而不特性配置 SOAP 扩展,SOAP 扩展可以存储数据的 SOAP 扩展应用于每个类。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. 此示例将保存在其中记录发往和来自基于到缓存实现 XML Web 服务的类名称的 XML Web 服务方法的 SOAP 消息文件的名称。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. 此代码示例是 TraceExtension SOAP 扩展可以在中找到一个完整的代码示例的一部分SoapExtension类概述。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:
   virtual Object^ GetInitializer( Type^ WebServiceType ) override
   {
      // Return a file name to log the trace information to based on the passed in type.
      return String::Format( "C:\\{0}.log", WebServiceType->FullName );
   }
// 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";    
}
' 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

注解

重载的GetInitializer,获取由调用 ASP.NET 取决于如何指定 SOAP 扩展。The overload of GetInitializer that gets called by ASP.NET depends on how the SOAP extension was specified. 有两种方法用于指定 SOAP 扩展:There are two methods for specifying a SOAP extension:

  • 应用自定义特性,派生自SoapExtensionAttribute,到单个 XML Web 服务方法。Apply a custom attribute, deriving from SoapExtensionAttribute, to the individual XML Web service method.

  • 在 web.config 或 app.config 配置文件中添加的引用。Add a reference in either the web.config or app.config configuration files.

如果添加一个配置文件的引用,该配置文件的作用域内的所有 XML Web 服务在都运行 SOAP 扩展。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. ASP.NET 在指定时,通过引用配置文件中,SOAP 扩展调用GetInitializer传入的重载TypeWhen specifying, a SOAP extension by referencing a configuration file, ASP.NET invokes the GetInitializer overload that passes in a Type. 通过应用自定义属性指定一个扩展,ASP.NET 将调用GetInitializer通过中LogicalMethodInfo和一个SoapExtensionAttributeWhen specifying an extension by applying a custom attribute, ASP.NET invokes the GetInitializer that passes in a LogicalMethodInfo and a SoapExtensionAttribute.

将 SOAP 扩展添加到配置文件的详细信息,请参阅XML Web 服务使用 ASP.NET 创建的配置选项For details on adding SOAP extensions to a configuration file, see Configuration Options for XML Web Services Created Using ASP.NET.

GetInitializer(LogicalMethodInfo, SoapExtensionAttribute)

当在派生类中重写时,允许 SOAP 扩展以一次执行的成本使用应用于 XML Web services 方法的特性来初始化特定于 XML Web services 方法的数据。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.

public:
 abstract System::Object ^ GetInitializer(System::Web::Services::Protocols::LogicalMethodInfo ^ methodInfo, System::Web::Services::Protocols::SoapExtensionAttribute ^ attribute);
public abstract object GetInitializer (System.Web.Services.Protocols.LogicalMethodInfo methodInfo, System.Web.Services.Protocols.SoapExtensionAttribute attribute);
abstract member GetInitializer : System.Web.Services.Protocols.LogicalMethodInfo * System.Web.Services.Protocols.SoapExtensionAttribute -> obj
Public MustOverride Function GetInitializer (methodInfo As LogicalMethodInfo, attribute As SoapExtensionAttribute) As Object

参数

methodInfo
LogicalMethodInfo

LogicalMethodInfo,它表示应用 SOAP 扩展的 XML Web services 方法的特定函数原型。A LogicalMethodInfo representing the specific function prototype for the XML Web service method to which the SOAP extension is applied.

attribute
SoapExtensionAttribute

应用于 XML Web services 方法的 SoapExtensionAttributeThe SoapExtensionAttribute applied to the XML Web service method.

返回

Object,SOAP 扩展将对其进行初始化以用于缓存。The Object that the SOAP extension initializes for caching.

示例

下面的代码演示如何获取 SOAP 扩展特定的数据传递中使用的类,派生自SoapExtensionAttribute,然后将其缓存中的数据和GetInitializerThe 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. 此代码示例的一个完整的代码示例摘自TraceExtension可在 SOAP 扩展SoapExtension类概述。This code example is part of a full code example for a TraceExtension SOAP extension that can be found in the SoapExtension class overview. 此代码示例依赖于TraceExtensionAttribute传递到attribute参数。This code example relies on a TraceExtensionAttribute being passed into the attribute parameter. 在完整的代码示例中,TraceExtensionAttribute派生自SoapExtensionAttribute,并添加Filename属性,它是什么GetInitializer在缓存中存储。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 override object GetInitializer(LogicalMethodInfo methodInfo,
    SoapExtensionAttribute attribute) 
{
    return ((TraceExtensionAttribute) attribute).Filename;
}
' When the SOAP extension is accessed for the first time, 
' cache the file name passed in by the SoapExtensionAttribute.

Public Overloads Overrides Function GetInitializer( _
    methodInfo As LogicalMethodInfo, _
    attribute As SoapExtensionAttribute) As Object    
    Return CType(attribute, TraceExtensionAttribute).Filename
End Function

注解

如果 SOAP 扩展的配置使用配置文件,请参阅GetInitializer接受重载TypeIf the SOAP extension is configured using a configuration file see the GetInitializer overload that accepts a Type.

SOAP 扩展有三个机会来初始化数据,并且它们都具有不同的用途:A SOAP extension has three opportunities to initialize data and they all have different purposes:

  • 类构造函数的每次 SOAP 扩展实例化并通常用来初始化成员变量,都会调用类构造函数。Class constructor - The class constructor is called every time a SOAP extension is instantiated and is typically used to initialize member variables.

  • GetInitializer - GetInitializer但是,将调用只是一次,第一次的 SOAP 请求对 XML Web services 方法。GetInitializer - GetInitializer, however, is called just once, the first time a SOAP request is made to an XML Web services method. 如果自定义特性应用于 XML Web 服务方法,GetInitializer调用方法。If a custom attribute is applied to the XML Web service method, the GetInitializer method is invoked. 这允许 SOAP 扩展以询问LogicalMethodInfo的 XML Web 服务方法原型的信息或访问特定于扩展的数据通过派生自的类传递SoapExtensionAttributeThis 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. 返回值可由 ASP.NET 缓存并传递给后续Initialize方法。The return value is cached by ASP.NET and passed into subsequent Initialize methods. 因此,进行的初始化GetInitializer实质上是封装到一次性的性能会下降。Therefore, initialization done in GetInitializer is encapsulated essentially into a one-time performance hit.

  • Initialize - Initialize 每次的 SOAP 请求对 XML Web 服务方法,但有类构造函数,其优点在于调用Object中初始化GetInitializer传递给它。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.

另请参阅

适用于