HOW TO:在設定 SOAP 擴充功能時初始化快取的資料
本主題專門說明舊有技術。 應該使用下列建立 XML Web Service 及 XML Web Service 用戶端: Windows Communication Foundation.
下列程式碼範例會根據 SOAP 擴充功能最終設定的方式,以不同方式將 GetInitializer 方法中的快取資料初始化。如果 SOAP 擴充功能是使用屬性 (在本例中為 TraceExtensionAttribute
) 所設定,則會快取這個屬性中指定的檔案名稱。如果 SOAP 擴充功能是使用組態檔設定的,則會根據 Web 服務的類型計算出快取的檔案名稱。
範例
' When the SOAP extension is accessed for the first time, the XML
' Web service method it is applied to is accessed to store the file
' name passed in, using the corresponding SoapExtensionAttribute.
Public Overloads Overrides Function GetInitializer(methodInfo As _
LogicalMethodInfo, attribute As SoapExtensionAttribute) As Object
Return CType(attribute, TraceExtensionAttribute).Filename
End Function
' The extension was configured to run using a configuration file
' instead of an attribute applied to a specific 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, based on the type.
Return "C:\" + WebServiceType.FullName + ".log"
End Function
// When the SOAP extension is accessed for the first time, the XML
// Web service method it is applied to is accessed to store the file
// name passed in, using the corresponding SoapExtensionAttribute.
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return ((TraceExtensionAttribute) attribute).Filename;
}
// The extension was configured to run using a configuration file instead of
// an attribute applied to a specific Web service method.
public override object GetInitializer(Type WebServiceType)
{
// Return a file name to log the trace information, based on the type.
return "C:\\" + WebServiceType.FullName + ".log";}