다음을 통해 공유


SoapFormatter 클래스

개체나 연결된 개체의 전체 그래프를 SOAP 형식으로 serialize 및 deserialize합니다.

네임스페이스: System.Runtime.Serialization.Formatters.Soap
어셈블리: System.Runtime.Serialization.Formatters.Soap(system.runtime.serialization.formatters.soap.dll)

구문

‘선언
Public NotInheritable Class SoapFormatter
    Implements IRemotingFormatter, IFormatter
‘사용 방법
Dim instance As SoapFormatter
public sealed class SoapFormatter : IRemotingFormatter, IFormatter
public ref class SoapFormatter sealed : IRemotingFormatter, IFormatter
public final class SoapFormatter implements IRemotingFormatter, IFormatter
public final class SoapFormatter implements IRemotingFormatter, IFormatter

설명

SoapFormatterBinaryFormatter 클래스는 IRemotingFormatter 인터페이스를 구현하여 RPC(원격 프로시저 호출)를 지원하고, IRemotingFormatter에서 상속된 IFormatter 인터페이스를 구현하여 개체 그래프의 serialization을 지원합니다. 또한 SoapFormatter 클래스는 IRemotingFormatter 기능을 사용하지 않고 ISoapMessage 개체를 사용하여 RPC를 지원합니다.

RPC를 수행하는 동안 IRemotingFormatter 인터페이스를 사용하면 서로 다른 두 개체의 그래프, 즉 serialize할 개체의 그래프와 원격 함수 호출에 대한 정보(예: 트랜잭션 ID나 메서드 시그니처)를 전달할 헤더 개체의 배열이 포함된 그래프를 지정할 수 있습니다. 성공적으로 serialize하려면 첫째 그래프의 루트 개체가 IMethodCallMessage 인터페이스나 IMethodReturnMessage 인터페이스 중 하나를 구현하는 개체여야 합니다.

RPC를 deserialize하는 동안 HeaderHandler 대리자가 포맷터의 Deserialize 메서드에 지정됩니다. 원격 인프라는 HeaderHandler 대리자를 사용하여 ISerializable 인터페이스를 지원하는 개체를 만듭니다. 이 개체는 헤더에 저장된 정보를 포함하고, deserializer가 반환하는 그래프의 루트가 됩니다.

또한 SoapFormatterISoapMessage 인터페이스를 구현하는 개체를 사용하여 만든 RPC도 처리할 수 있습니다. IRemotingFormatter 기능을 사용하지 않고 RPC를 만들려면 ISoapMessage 인터페이스를 지원하는 개체를 serialize될 그래프의 루트에 배치합니다. 이러한 방법으로 만든 RPC를 deserialize하려면 TopObject 속성이 ISoapMessage 인터페이스를 지원하고 관련 원격 호출 정보를 포함하는 다른 개체로 설정되어야 합니다.

TimeSpan Serialization

TimeSpan 개체는 ISO 8601: 1998, 5.5.3.2.1항 "Alternative" 표준에 따라 serialize됩니다.

버전 정보

SoapFormatter는 .NET Framework 버전 간의 serialization 호환성을 지원하지 않습니다. 따라서 Framework 버전 1.1 형식과 2.0 형식 간의 serialization은 실패할 수 있습니다. 이 문제를 해결하려면 다음을 수행합니다.

  • 1.1과 2.0 간의 호환성을 제공하는 BinaryFormatter를 사용하도록 변환합니다.

  • 보관된 기존 데이터를 새 형식으로 변환합니다.

  • serialize된 데이터의 생산자와 소비자를 모두 버전 2.0으로 변환합니다.

  • 1.1에서 2.0으로 변경된 형식은 사용하지 않습니다.

예제

Imports System.IO
Imports System.Collections
Imports System.Runtime.Serialization

' Note: When building this code, you must reference the
' System.Runtime.Serialization.Formatters.Soap.dll assembly.
Imports System.Runtime.Serialization.Formatters.Soap


Module App

   Sub Main()
      Serialize()
      Deserialize()
   End Sub

   Sub Serialize()
      ' Create a hashtable of values that will eventually be serialized.
      Dim addresses As New Hashtable
      addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052")
      addresses.Add("Fred", "987 Pine Road, Phila., PA 19116")
      addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301")

      ' To serialize the hashtable (and its key/value pairs), 
      ' you must first open a stream for writing.
      ' Use a file stream here.
      Dim fs As New FileStream("DataFile.soap", FileMode.Create)

      ' Construct a SoapFormatter and use it 
      ' to serialize the data to the stream.
      Dim formatter As New SoapFormatter
      Try
         formatter.Serialize(fs, addresses)
      Catch e As SerializationException
         Console.WriteLine("Failed to serialize. Reason: " & e.Message)
         Throw
      Finally
         fs.Close()
      End Try
   End Sub


   Sub Deserialize()
      ' Declare the hashtable reference.
      Dim addresses As Hashtable = Nothing

      ' Open the file containing the data that you want to deserialize.
      Dim fs As New FileStream("DataFile.soap", FileMode.Open)
      Try
         Dim formatter As New SoapFormatter

         ' Deserialize the hashtable from the file and 
         ' assign the reference to the local variable.
         addresses = DirectCast(formatter.Deserialize(fs), Hashtable)
      Catch e As SerializationException
         Console.WriteLine("Failed to deserialize. Reason: " & e.Message)
         Throw
      Finally
         fs.Close()
      End Try

      ' To prove that the table deserialized correctly, 
      ' display the key/value pairs to the console.
      Dim de As DictionaryEntry
      For Each de In addresses
         Console.WriteLine("{0} lives at {1}.", de.Key, de.Value)
      Next
   End Sub
End Module
using System;
using System.IO;
using System.Collections;
using System.Runtime.Serialization;

// Note: When building this code, you must reference the
// System.Runtime.Serialization.Formatters.Soap.dll assembly.
using System.Runtime.Serialization.Formatters.Soap;


class App 
{
    [STAThread]
    static void Main() 
    {
        Serialize();
        Deserialize();
    }

    static void Serialize() 
    {
        // Create a hashtable of values that will eventually be serialized.
        Hashtable addresses = new Hashtable();
        addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052");
        addresses.Add("Fred", "987 Pine Road, Phila., PA 19116");
        addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301");

        // To serialize the hashtable (and its key/value pairs), 
        // you must first open a stream for writing.
        // Use a file stream here.
        FileStream fs = new FileStream("DataFile.soap", FileMode.Create);

        // Construct a SoapFormatter and use it 
        // to serialize the data to the stream.
        SoapFormatter formatter = new SoapFormatter();
        try 
        {
            formatter.Serialize(fs, addresses);
        }
        catch (SerializationException e) 
        {
            Console.WriteLine("Failed to serialize. Reason: " + e.Message);
            throw;
        }
        finally 
        {
            fs.Close();
        }
    }

   
    static void Deserialize() 
    {
        // Declare the hashtable reference.
        Hashtable addresses  = null;

        // Open the file containing the data that you want to deserialize.
        FileStream fs = new FileStream("DataFile.soap", FileMode.Open);
        try 
        {
            SoapFormatter formatter = new SoapFormatter();

            // Deserialize the hashtable from the file and 
            // assign the reference to the local variable.
            addresses = (Hashtable) formatter.Deserialize(fs);
        }
        catch (SerializationException e) 
        {
            Console.WriteLine("Failed to deserialize. Reason: " + e.Message);
            throw;
        }
        finally 
        {
            fs.Close();
        }

        // To prove that the table deserialized correctly, 
        // display the key/value pairs to the console.
        foreach (DictionaryEntry de in addresses) 
        {
            Console.WriteLine("{0} lives at {1}.", de.Key, de.Value);
        }
    }
}
#using <system.dll>
#using <system.runtime.serialization.formatters.soap.dll>

using namespace System;
using namespace System::IO;
using namespace System::Collections;
using namespace System::Runtime::Serialization;
using namespace System::Runtime::Serialization::Formatters::Soap;
void Serialize()
{
   
   // Create a hashtable of values that will eventually be serialized.
   Hashtable^ addresses = gcnew Hashtable;
   addresses->Add( "Jeff", "123 Main Street, Redmond, WA 98052" );
   addresses->Add( "Fred", "987 Pine Road, Phila., PA 19116" );
   addresses->Add( "Mary", "PO Box 112233, Palo Alto, CA 94301" );
   
   // To serialize the hashtable (and its keys/values), 
   // you must first open a stream for writing.
   // We will use a file stream here.
   FileStream^ fs = gcnew FileStream( "DataFile.soap",FileMode::Create );
   
   // Construct a SoapFormatter and use it 
   // to serialize the data to the stream.
   SoapFormatter^ formatter = gcnew SoapFormatter;
   try
   {
      formatter->Serialize( fs, addresses );
   }
   catch ( SerializationException^ e ) 
   {
      Console::WriteLine( "Failed to serialize. Reason: {0}", e->Message );
      throw;
   }
   finally
   {
      fs->Close();
   }

}

void Deserialize()
{
   
   // Declare the hashtable reference.
   Hashtable^ addresses = nullptr;
   
   // Open the file containing the data that we want to deserialize.
   FileStream^ fs = gcnew FileStream( "DataFile.soap",FileMode::Open );
   try
   {
      SoapFormatter^ formatter = gcnew SoapFormatter;
      
      // Deserialize the hashtable from the file and 
      // assign the reference to our local variable.
      addresses = dynamic_cast<Hashtable^>(formatter->Deserialize( fs ));
   }
   catch ( SerializationException^ e ) 
   {
      Console::WriteLine( "Failed to deserialize. Reason: {0}", e->Message );
      throw;
   }
   finally
   {
      fs->Close();
   }

   
   // To prove that the table deserialized correctly, 
   // display the keys/values to the console.
   IEnumerator^ myEnum = addresses->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      DictionaryEntry^ de = safe_cast<DictionaryEntry^>(myEnum->Current);
      Console::WriteLine( " {0} lives at {1}.", de->Key, de->Value );
   }
}


[STAThread]
int main()
{
   Serialize();
   Deserialize();
}
import System.*;
import System.IO.*;
import System.Collections.*;
import System.Runtime.Serialization.*;
// Note: When building this code, you must reference the
// System.Runtime.Serialization.Formatters.Soap.dll assembly.
import System.Runtime.Serialization.Formatters.Soap.*;

class App
{
    /** @attribute STAThread()
     */
    public static void main(String[] args) throws SerializationException
    {
        Serialize();
        Deserialize();
    } //main

    static void Serialize() throws SerializationException
    {
        // Create a hashtable of values that will eventually be serialized.
        Hashtable addresses = new Hashtable();
        addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052");
        addresses.Add("Fred", "987 Pine Road, Phila., PA 19116");
        addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301");
        // To serialize the hashtable (and its key/value pairs), 
        // you must first open a stream for writing.
        // Use a file stream here.
        FileStream fs = new FileStream("DataFile.soap", FileMode.Create);
        // Construct a SoapFormatter and use it 
        // to serialize the data to the stream.
        SoapFormatter formatter = new SoapFormatter();
        try {
            formatter.Serialize(fs, addresses);
        }
        catch (SerializationException e) {
            Console.WriteLine("Failed to serialize. Reason: " 
                + e.get_Message());
            throw e;
        }
        finally {
            fs.Close();
        }
    } //Serialize

    static void Deserialize() throws SerializationException
    {
        // Declare the hashtable reference.
        Hashtable addresses = null;
        // Open the file containing the data that you want to deserialize.
        FileStream fs = new FileStream("DataFile.soap", FileMode.Open);
        try {
            SoapFormatter formatter = new SoapFormatter();
            // Deserialize the hashtable from the file and 
            // assign the reference to the local variable.
            addresses = (Hashtable)formatter.Deserialize(fs);
        }
        catch (SerializationException e) {
            Console.WriteLine("Failed to deserialize. Reason: " 
                + e.get_Message());
            throw e;
        }
        finally {
            fs.Close();
        }
        
        // To prove that the table deserialized correctly, 
        // display the key/value pairs to the console.
        IEnumerator myEnumerator = addresses.GetEnumerator();
        while (myEnumerator.MoveNext()) {
            DictionaryEntry de = (DictionaryEntry)myEnumerator.get_Current();
            Console.WriteLine("{0} lives at {1}.", de.get_Key(), 
                de.get_Value());
        }
    } //Deserialize
} //App

상속 계층 구조

System.Object
  System.Runtime.Serialization.Formatters.Soap.SoapFormatter

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

SoapFormatter 멤버
System.Runtime.Serialization.Formatters.Soap 네임스페이스