Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

SoapMessage Class

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

Namespace: System.Web.Services.Protocols
Assembly: System.Web.Services (in system.web.services.dll)
public abstract class SoapMessage
public abstract class SoapMessage
public abstract class SoapMessage
Not applicable.

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.

// 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 void ProcessMessage(SoapMessage message) throws Exception
{
    switch (message.get_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");
    }
} //ProcessMessage

// 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.get_Now());
    myStreamWriter.WriteLine("The method that has been invoked is: ");
    myStreamWriter.WriteLine("\t" + message.get_MethodInfo());

    myStreamWriter.WriteLine("The contents of the SOAPAction HTTP "
        + "header is:");
    myStreamWriter.WriteLine("\t" + message.get_Action());

    myStreamWriter.WriteLine("The contents of HTTP Content-type "
        + "header is:");
    myStreamWriter.WriteLine("\t" + message.get_ContentType());

    if (message.get_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.get_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();
} //WriteOutputBeforeSerialize

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

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.