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调用 方法时, SoapExtension 在每个 SoapMessageStage处接收 SoapMessage 。 由特定的 SOAP 扩展选择如何处理 SoapMessage。 常见的 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

从对 XML Web services 方法的调用中获取 SoapException

Headers

应用于当前 SOAP 请求或 SOAP 响应的 SOAP 标头的集合。

MethodInfo

当在派生类中重写时,获取为要其发出 SOAP 请求的 XML Web services 方法的方法原型的表示形式。

OneWay

获取一个值,该值指示应用于 XML Web services 方法的 OneWaySoapDocumentMethodAttribute 特性的 SoapRpcMethodAttribute 属性。

SoapVersion

获取用于与 XML Web services 进行通信的 SOAP 协议的版本。

Stage

获取 SoapMessageStageSoapMessage

Stream

获取以 Stream 形式表示 SOAP 请求或 SOAP 响应的数据。

Url

当在派生类中重写时,获取 XML Web services 的基 URL。

方法

EnsureInStage()

当在派生类中被重写时,断言当前 SoapMessageStage 为可以使用 in 参数的阶段。

EnsureOutStage()

当在派生类中被重写时,断言当前 SoapMessageStage 阶段是不可以使用 out 参数的阶段。

EnsureStage(SoapMessageStage)

确保对 XML Web services 方法的调用的 SoapMessageStage 是传入的阶段。 如果当前处理阶段不是传入的阶段之一,则引发异常。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetInParameterValue(Int32)

在指定索引处获取传递到 XML Web services 方法中的参数。

GetOutParameterValue(Int32)

在指定索引处获取传递到 XML Web services 方法中的输出参数。

GetReturnValue()

获取 XML Web services 方法的返回值。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于