SoapMessage Class (System.Web.Services.Protocols)

Switch View :
ScriptFree
.NET Framework Class Library
SoapMessage Class

Represents the data in a SOAP request or SOAP response at a specific SoapMessageStage.

Inheritance Hierarchy

System.Object
  System.Web.Services.Protocols.SoapMessage
    System.Web.Services.Protocols.SoapClientMessage
    System.Web.Services.Protocols.SoapServerMessage

Namespace:  System.Web.Services.Protocols
Assembly:  System.Web.Services (in System.Web.Services.dll)
Syntax

Visual Basic
<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
Public MustInherit Class SoapMessage
C#
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class SoapMessage
Visual C++
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")]
public ref class SoapMessage abstract
F#
[<AbstractClass>]
[<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")>]
type SoapMessage =  class end

The SoapMessage type exposes the following members.

Properties

  Name Description
Public property Action When overridden in a derived class, gets the SOAPAction HTTP request header field for the SOAP request or SOAP response.
Public property ContentEncoding Gets or sets the contents of the Content-Encoding HTTP header.
Public property ContentType Gets or sets the HTTP Content-Type of the SOAP request or SOAP response.
Public property Exception Gets the SoapException from the call to the XML Web service method.
Public property Headers A collection of the SOAP headers applied to the current SOAP request or SOAP response.
Public property MethodInfo When overridden in a derived class, gets a representation of the method prototype for the XML Web service method for which the SOAP request is intended.
Public property OneWay Gets a value indicating the SoapDocumentMethodAttribute.OneWay property of either the SoapDocumentMethodAttribute or the SoapRpcMethodAttribute attribute applied to the XML Web service method.
Public property SoapVersion Gets the version of the SOAP protocol used to communicate with the XML Web service.
Public property Stage Gets the SoapMessageStage of the SoapMessage.
Public property Stream Gets the data representing the SOAP request or SOAP response in the form of a Stream.
Public property Url When overridden in a derived class, gets the base URL of the XML Web service.
Top
Methods

  Name Description
Protected method EnsureInStage When overridden in a derived class, asserts that the current SoapMessageStage is a stage where in parameters are available.
Protected method EnsureOutStage When overridden in a derived class, asserts that the current SoapMessageStage stage is a stage where out parameters are available.
Protected method EnsureStage Ensures that the SoapMessageStage of the call to the XML Web service method is the stage or stages passed in. If the current processing stage is not one of the stages passed in, an exception is thrown.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetInParameterValue Gets the parameter passed into the XML Web service method at the specified index.
Public method GetOutParameterValue Gets the out parameter passed into the XML Web service method at the specified index.
Public method GetReturnValue Gets the return value of an XML Web service method.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Remarks

The primary use of the SoapMessage class is for SOAP extensions, representing the data in a SOAP request or SOAP response. When the ProcessMessage method is called, a SoapExtension receives a SoapMessage at each SoapMessageStage. It is up to the particular SOAP extension to choose how to process the SoapMessage. Common SOAP extensions include encryption and compression.

SOAP extensions can be applied to either or both an XML Web service method created using ASP.NET or an XML Web service client. When a SOAP extension is applied to an XML Web service method, the ProcessMessage method receives an instance of SoapServerMessage, which derives from SoapMessage. Likewise, when a SOAP extension is applied to an XML Web service client, ProcessMessage receives an instance of SoapClientMessage.

Examples

Visual Basic

   ' 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 'ProcessMessage

   ' 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 'WriteOutputBeforeSerialize

   ' 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 'WriteInputAfterDeserialize



C#

   // 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();
   }



Visual C++

// 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();
}


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference