共用方式為


SoapMessage 類別

定義

表示特定 SoapMessageStage 的 SOAP 要求或 SOAP 回應中的資料。

public ref class SoapMessage abstract
public abstract class SoapMessage
type SoapMessage = class
Public MustInherit Class SoapMessage
繼承
SoapMessage
衍生

範例

// Process the SOAP message received and write to log file.
virtual void ProcessMessage( SoapMessage^ message ) override
{
   switch ( message->Stage )
   {
      case SoapMessageStage::BeforeSerialize:
         WriteOutputBeforeSerialize( message );
         break;
      case SoapMessageStage::AfterSerialize:
         WriteOutputAfterSerialize( message );
         break;
      case SoapMessageStage::BeforeDeserialize:
         WriteInputBeforeDeserialize( message );
         break;
      case SoapMessageStage::AfterDeserialize:
         WriteInputAfterDeserialize( message );
         break;
      default:
         throw gcnew Exception( "invalid stage" );
   }
}

// Write the contents of the outgoing SOAP message to the log file.
void WriteOutputBeforeSerialize( SoapMessage^ message )
{
   FileStream^ myFileStream =
      gcnew FileStream( filename, FileMode::Append, FileAccess::Write );
   StreamWriter^ myStreamWriter = gcnew StreamWriter( myFileStream );
   myStreamWriter->WriteLine( "================================== Request at {0}",
      DateTime::Now );
   
   myStreamWriter->WriteLine(
      "The method that has been invoked is: " );
   myStreamWriter->WriteLine( "\t{0}", message->MethodInfo );

   myStreamWriter->WriteLine( "The contents of the SOAPAction HTTP header is:" );
   myStreamWriter->WriteLine( "\t{0}", message->Action );

   myStreamWriter->WriteLine( "The contents of HTTP Content-type header is:" );
   myStreamWriter->WriteLine( "\t{0}", message->ContentType );

   if ( message->OneWay )
   {
      myStreamWriter->WriteLine(
         "The method invoked on the client shall not wait"
         + " till the server finishes" );
   }
   else
   {
      myStreamWriter->WriteLine(
         "The method invoked on the client shall wait"
         + " till the server finishes" );
   }

   myStreamWriter->WriteLine(
      "The site where the XML Web service is available is:" );
   myStreamWriter->WriteLine( "\t{0}", message->Url );

   myStreamWriter->WriteLine( "The values of the in parameters are:" );
   myStreamWriter->WriteLine(
      "Value of first in parameter: {0}", message->GetInParameterValue( 0 ) );
   myStreamWriter->WriteLine(
      "Value of second in parameter: {0}", message->GetInParameterValue( 1 ) );

   myStreamWriter->WriteLine();
   myStreamWriter->Flush();
   myStreamWriter->Close();
   myFileStream->Close();
}

// Write the contents of the incoming SOAP message to the log file.
void WriteInputAfterDeserialize( SoapMessage^ message )
{
   FileStream^ myFileStream =
      gcnew FileStream( filename, FileMode::Append, FileAccess::Write );
   StreamWriter^ myStreamWriter = gcnew StreamWriter( myFileStream );
   myStreamWriter->WriteLine();
   
   myStreamWriter->WriteLine( "The values of the out parameter are:" );
   myStreamWriter->WriteLine(
      "The value of the out parameter is: {0}", message->GetOutParameterValue( 0 ) );

   myStreamWriter->WriteLine( "The values of the return parameter are:" );
   myStreamWriter->WriteLine(
      "The value of the return parameter is: {0}", message->GetReturnValue() );

   myStreamWriter->Flush();
   myStreamWriter->Close();
   myFileStream->Close();
}
// Process the SOAP message received and write to log file.
public override void ProcessMessage(SoapMessage message)
{
   switch (message.Stage)
   {
      case SoapMessageStage.BeforeSerialize:
         WriteOutputBeforeSerialize(message);
         break;
      case SoapMessageStage.AfterSerialize:
         WriteOutputAfterSerialize(message);
         break;
      case SoapMessageStage.BeforeDeserialize:
         WriteInputBeforeDeserialize(message);
         break;
      case SoapMessageStage.AfterDeserialize:
         WriteInputAfterDeserialize(message);
         break;
      default:
         throw new Exception("invalid stage");
   }
}

// Write the contents of the outgoing SOAP message to the log file.
public void WriteOutputBeforeSerialize(SoapMessage message)
{
   FileStream myFileStream =
      new FileStream(filename, FileMode.Append, FileAccess.Write);
   StreamWriter myStreamWriter = new StreamWriter(myFileStream);
   myStreamWriter.WriteLine("================================== Request at "
      + DateTime.Now);
   myStreamWriter.WriteLine("The method that has been invoked is: ");
   myStreamWriter.WriteLine("\t" + message.MethodInfo);
   myStreamWriter.WriteLine(
      "The contents of the SOAPAction HTTP header is:");
   myStreamWriter.WriteLine("\t" + message.Action);
   myStreamWriter.WriteLine("The contents of HTTP Content-type header is:");
   myStreamWriter.WriteLine("\t" + message.ContentType);
   if(message.OneWay)
      myStreamWriter.WriteLine(
         "The method invoked on the client shall not wait"
         + " till the server finishes");
   else
      myStreamWriter.WriteLine(
         "The method invoked on the client shall wait"
         + " till the server finishes");
   myStreamWriter.WriteLine(
      "The site where the XML Web service is available is:");
   myStreamWriter.WriteLine("\t" + message.Url);
   myStreamWriter.WriteLine("The values of the in parameters are:");
   myStreamWriter.WriteLine("Value of first in parameter: {0}",
      message.GetInParameterValue(0));
   myStreamWriter.WriteLine("Value of second in parameter: {0}",
      message.GetInParameterValue(1));
   myStreamWriter.WriteLine();
   myStreamWriter.Flush();
   myStreamWriter.Close();
   myFileStream.Close();
}

// Write the contents of the incoming SOAP message to the log file.
public void WriteInputAfterDeserialize(SoapMessage message)
{
   FileStream myFileStream =
      new FileStream(filename, FileMode.Append, FileAccess.Write);
   StreamWriter myStreamWriter = new StreamWriter(myFileStream);
   myStreamWriter.WriteLine();
   myStreamWriter.WriteLine("The values of the out parameter are:");
   myStreamWriter.WriteLine("The value of the out parameter is: {0}",
      message.GetOutParameterValue(0));
   myStreamWriter.WriteLine("The values of the return parameter are:");
   myStreamWriter.WriteLine("The value of the return parameter is: {0}",
      message.GetReturnValue());
   myStreamWriter.Flush();
   myStreamWriter.Close();
   myFileStream.Close();
}
' Process the SOAP message received and write to log file.
Public Overrides Sub ProcessMessage(message As SoapMessage)
   Select Case message.Stage
      Case SoapMessageStage.BeforeSerialize
         WriteOutputBeforeSerialize(message)
      Case SoapMessageStage.AfterSerialize
         WriteOutputAfterSerialize(message)
      Case SoapMessageStage.BeforeDeserialize
         WriteInputBeforeDeserialize(message)
      Case SoapMessageStage.AfterDeserialize
         WriteInputAfterDeserialize(message)
      Case Else
            Throw New Exception("invalid stage")
   End Select
End Sub

' Write the contents of the outgoing SOAP message to the log file.
Public Sub WriteOutputBeforeSerialize(message As SoapMessage)
   Dim myFileStream As New FileStream( _
      filename, FileMode.Append, FileAccess.Write)
   Dim myStreamWriter As New StreamWriter(myFileStream)
   myStreamWriter.WriteLine( _
      "================================== Request at " & _
      DateTime.Now)
   myStreamWriter.WriteLine("The method that has been invoked is: ")
   myStreamWriter.WriteLine(ControlChars.Tab & message.MethodInfo.ToString())
   myStreamWriter.WriteLine("The contents of the SOAPAction HTTP header is:")
   myStreamWriter.WriteLine(ControlChars.Tab & message.Action)
   myStreamWriter.WriteLine("The contents of HTTP Content-type header is:")
   myStreamWriter.WriteLine(ControlChars.Tab & message.ContentType)
   If message.OneWay Then
      myStreamWriter.WriteLine( _
         "The method invoked on the client shall not wait" & _
         " till the server finishes")
   Else
      myStreamWriter.WriteLine( _
         "The method invoked on the client shall wait" & _
         " till the server finishes")
   End If
   myStreamWriter.WriteLine( _
      "The site where the XML Web service is available is: ")
   myStreamWriter.WriteLine(ControlChars.Tab & message.Url)
   myStreamWriter.WriteLine("The values of the in parameters are:")
   myStreamWriter.WriteLine("Value of first in parameter: {0}", _
      message.GetInParameterValue(0))
   myStreamWriter.WriteLine("Value of second in parameter: {0}", _
      message.GetInParameterValue(1))
   myStreamWriter.WriteLine()
   myStreamWriter.Flush()
   myStreamWriter.Close()
   myFileStream.Close()
End Sub

' Write the contents of the incoming SOAP message to the log file.
Public Sub WriteInputAfterDeserialize(message As SoapMessage)
   Dim myFileStream As _
      New FileStream(filename, FileMode.Append, FileAccess.Write)
   Dim myStreamWriter As New StreamWriter(myFileStream)
   myStreamWriter.WriteLine()
   myStreamWriter.WriteLine("The values of the out parameter are:")
   myStreamWriter.WriteLine("The value of the out parameter is: {0}", _
      message.GetOutParameterValue(0))
   myStreamWriter.WriteLine("The values of the return parameter are:")
   myStreamWriter.WriteLine("The value of the return parameter is: {0}", _
      message.GetReturnValue())
   myStreamWriter.Flush()
   myStreamWriter.Close()
   myFileStream.Close()
End Sub

備註

類別的主要用途 SoapMessage 是 SOAP 延伸模組,代表 SOAP 要求或 SOAP 回應中的資料。 ProcessMessage呼叫 方法時, SoapExtensionSoapMessageSoapMessageStage 在每個 接收 。 您可以選擇如何處理 SoapMessage 的特定 SOAP 擴充功能。 常見的 SOAP 延伸模組包括加密和壓縮。

SOAP 延伸模組可以套用至使用 ASP.NET 或 XML Web 服務用戶端建立的 XML Web 服務方法。 當 SOAP 延伸模組套用至 XML Web 服務方法時, ProcessMessage 方法會接收 衍生自 SoapMessageSoapServerMessage 實例。 同樣地,當 SOAP 延伸模組套用至 XML Web 服務用戶端時, ProcessMessage 會收到 的 SoapClientMessage 實例。

屬性

Action

當在衍生類別中覆寫時,取得 SOAP 要求或 SOAP 回應的 SOAPAction HTTP 要求標頭欄位。

ContentEncoding

取得或設定 Content-Encoding HTTP 標頭的內容。

ContentType

取得或設定 SOAP 要求或 SOAP 回應的 HTTP Content-Type

Exception

取得 SoapException,其因呼叫 XML Web Service 方法而造成的。

Headers

套用至目前 SOAP 要求或 SOAP 回應的 SOAP 標頭集合。

MethodInfo

當在衍生類別中覆寫時,取得 SOAP 要求所適用的 XML Web Service 方法的方法原型 (Prototype) 表示。

OneWay

取得值,指出套用至 XML Web Service 方法之 OneWaySoapDocumentMethodAttribute 屬性 (Attribute) 的 SoapRpcMethodAttribute 屬性 (Property)。

SoapVersion

取得用來與 XML Web Service 通訊的 SOAP 通訊協定版本。

Stage

取得 SoapMessageStageSoapMessage

Stream

取得以 Stream 形式表示的 SOAP 要求或 SOAP 回應的資料。

Url

在衍生類別中覆寫時,取得 XML Web Service 的基礎 URL。

方法

EnsureInStage()

當在衍生類別中覆寫時,判斷提示 (Assert) 目前的 SoapMessageStage 是可以取得 in 參數的階段。

EnsureOutStage()

當在衍生類別中覆寫時,判斷提示目前的 SoapMessageStage 階段是可以取得 out 參數的階段。

EnsureStage(SoapMessageStage)

確認呼叫 XML Web Service 方法的 SoapMessageStage 是傳入的階段。 如果目前的處理階段不是傳入的其中一個階段,則擲回例外狀況。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetInParameterValue(Int32)

在指定的索引處取得傳入 XML Web Service 方法的參數。

GetOutParameterValue(Int32)

在指定索引處取得傳入 XML Web Service 方法的 out 參數。

GetReturnValue()

取得 XML Web Service 方法的傳回值。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於