SoapExtension.Initialize(Object) 方法

定义

当在派生类中被重写时,允许 SOAP 扩展使用缓存于 GetInitializer(LogicalMethodInfo, SoapExtensionAttribute) 方法中的数据初始化其自身。When overridden in a derived class, allows a SOAP extension to initialize itself using the data cached in the GetInitializer(LogicalMethodInfo, SoapExtensionAttribute) method.

public:
 abstract void Initialize(System::Object ^ initializer);
public abstract void Initialize (object initializer);
abstract member Initialize : obj -> unit
Public MustOverride Sub Initialize (initializer As Object)

参数

initializer
Object

Object 从 ASP.NET 缓存的 GetInitializer(LogicalMethodInfo, SoapExtensionAttribute) 中返回。The Object returned from GetInitializer(LogicalMethodInfo, SoapExtensionAttribute) cached by ASP.NET.

示例

下面的示例演示如何使用在过程缓存的数据GetInitializer方法。The following example demonstrates how you can use the data cached during the GetInitializer method.

   // Receive the file name stored by GetInitializer and store it in
   // a member variable for this specific instance.
public:
   virtual void Initialize( Object^ initializer ) override
   {
      filename = dynamic_cast<String^>(initializer);
   }
// Receive the file name stored by GetInitializer and store it in
// a member variable for this specific instance.
public override void Initialize(object initializer) {
    filename = (string) initializer;
}
' Receive the file name stored by GetInitializer and store it in a 
' member variable for this specific instance.
Public Overrides Sub Initialize(initializer As Object)
    m_filename = CStr(initializer)
End Sub

注解

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

备注

此外可以添加 SOAP 扩展,而无需派生自SoapExtensionAttribute通过使用 <soapExtensionTypes > 元素配置文件中。You can also add a SOAP extension without deriving from SoapExtensionAttribute by using the <soapExtensionTypes> Element in a configuration file. 有关详细信息,请参阅 <soapExtensionTypes > 元素消息使用 SOAP 扩展修改 SOAPFor details, see <soapExtensionTypes> Element and SOAP Message Modification Using SOAP Extensions.

适用于