SoapTypeAttribute 클래스

정의

클래스 인스턴스를 SOAP 인코딩된 XML로 serialize할 때 XmlSerializer에 의해 생성되는 스키마를 제어합니다.

public ref class SoapTypeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct)]
public class SoapTypeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct)>]
type SoapTypeAttribute = class
    inherit Attribute
Public Class SoapTypeAttribute
Inherits Attribute
상속
SoapTypeAttribute
특성

예제

다음 예제에서는 라는 클래스를 직렬화 Group합니다. " SoapTypeAttribute SoapGroupType"으로 TypeName 설정된 클래스에 적용됩니다. 또한 재정의 SoapTypeAttribute 되어 "팀"으로 변경 TypeName 됩니다. 두 버전 모두 직렬화되어 SoapType.xml 및 SoapType2.xml 두 개의 파일이 생성됩니다.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

[SoapType("EmployeeType")]
public ref class Employee
{
public:
   String^ Name;
};


// The SoapType is overridden when the
// SerializeOverride  method is called.

[SoapType("SoapGroupType","http://www.cohowinery.com")]
public ref class Group
{
public:
   String^ GroupName;
   array<Employee^>^Employees;
};

public ref class Run
{
public:
   void SerializeOriginal( String^ filename )
   {
      // Create an instance of the XmlSerializer class that
      // can be used for serializing as a SOAP message.
      XmlTypeMapping^ mapp = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid );
      XmlSerializer^ mySerializer = gcnew XmlSerializer( mapp );

      // Writing the file requires a TextWriter.
      TextWriter^ writer = gcnew StreamWriter( filename );

      // Create an XML text writer.
      XmlTextWriter^ xmlWriter = gcnew XmlTextWriter( writer );
      xmlWriter->Formatting = Formatting::Indented;
      xmlWriter->Indentation = 2;

      // Create an instance of the class that will be serialized.
      Group^ myGroup = gcnew Group;

      // Set the Object* properties.
      myGroup->GroupName = ".NET";
      Employee^ e1 = gcnew Employee;
      e1->Name = "Pat";
      myGroup->Employees = gcnew array<Employee^>(1);
      myGroup->Employees[ 0 ] = e1;

      // Write the root element.
      xmlWriter->WriteStartElement( "root" );

      // Serialize the class.
      mySerializer->Serialize( xmlWriter, myGroup );

      // Close the root tag.
      xmlWriter->WriteEndElement();

      // Close the XmlWriter.
      xmlWriter->Close();

      // Close the TextWriter.
      writer->Close();
   }

   void SerializeOverride( String^ filename )
   {
      // Create an instance of the XmlSerializer class that
      // uses a SoapAttributeOverrides Object*.
      XmlSerializer^ mySerializer = CreateOverrideSerializer();

      // Writing the file requires a TextWriter.
      TextWriter^ writer = gcnew StreamWriter( filename );

      // Create an XML text writer.
      XmlTextWriter^ xmlWriter = gcnew XmlTextWriter( writer );
      xmlWriter->Formatting = Formatting::Indented;
      xmlWriter->Indentation = 2;

      // Create an instance of the class that will be serialized.
      Group^ myGroup = gcnew Group;

      // Set the Object* properties.
      myGroup->GroupName = ".NET";
      Employee^ e1 = gcnew Employee;
      e1->Name = "Pat";
      myGroup->Employees = gcnew array<Employee^>(1);
      myGroup->Employees[ 0 ] = e1;

      // Write the root element.
      xmlWriter->WriteStartElement( "root" );

      // Serialize the class.
      mySerializer->Serialize( xmlWriter, myGroup );

      // Close the root tag.
      xmlWriter->WriteEndElement();

      // Close the XmlWriter.
      xmlWriter->Close();

      // Close the TextWriter.
      writer->Close();
   }

   void DeserializeObject( String^ filename )
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer^ mySerializer = CreateOverrideSerializer();

      // Reading the file requires a TextReader.
      TextReader^ reader = gcnew StreamReader( filename );

      // Create an XML text reader.
      XmlTextReader^ xmlReader = gcnew XmlTextReader( reader );
      xmlReader->ReadStartElement();

      // Deserialize and cast the object.
      Group^ myGroup;
      myGroup = dynamic_cast<Group^>(mySerializer->Deserialize( xmlReader ));
      xmlReader->ReadEndElement();
      Console::WriteLine( "The GroupName is {0}", myGroup->GroupName );
      Console::WriteLine( "Look at the SoapType.xml and SoapType2.xml "
      "files for the generated XML." );

      // Close the readers.
      xmlReader->Close();
      reader->Close();
   }

private:
   XmlSerializer^ CreateOverrideSerializer()
   {
      // Create and return an XmlSerializer instance used to
      //  and create SOAP messages.
      SoapAttributeOverrides^ mySoapAttributeOverrides = gcnew SoapAttributeOverrides;
      SoapAttributes^ soapAtts = gcnew SoapAttributes;

      // Override the SoapTypeAttribute.
      SoapTypeAttribute^ soapType = gcnew SoapTypeAttribute;
      soapType->TypeName = "Team";
      soapType->IncludeInSchema = false;
      soapType->Namespace = "http://www.microsoft.com";
      soapAtts->SoapType = soapType;
      mySoapAttributeOverrides->Add( Group::typeid, soapAtts );

      // Create an XmlTypeMapping that is used to create an instance 
      // of the XmlSerializer. Then return the XmlSerializer Object*.
      XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter( mySoapAttributeOverrides ))->ImportTypeMapping( Group::typeid );
      XmlSerializer^ ser = gcnew XmlSerializer( myMapping );
      return ser;
   }
};

int main()
{
   Run^ test = gcnew Run;
   test->SerializeOriginal( "SoapType.xml" );
   test->SerializeOverride( "SoapType2.xml" );
   test->DeserializeObject( "SoapType2.xml" );
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// The SoapType is overridden when the
// SerializeOverride  method is called.
[SoapType("SoapGroupType", "http://www.cohowinery.com")]
public class Group
{
   public string GroupName;
   public Employee[] Employees;
}

[SoapType("EmployeeType")]
public class Employee
{
   public string Name;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeOriginal("SoapType.xml");
      test.SerializeOverride("SoapType2.xml");
      test.DeserializeObject("SoapType2.xml");
   }

   public void SerializeOriginal(string filename)
   {
      // Create an instance of the XmlSerializer class that
      // can be used for serializing as a SOAP message.
      XmlTypeMapping mapp =
         (new SoapReflectionImporter()).ImportTypeMapping(typeof(Group));
      XmlSerializer mySerializer = new XmlSerializer(mapp);

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an XML text writer.
      XmlTextWriter xmlWriter = new XmlTextWriter(writer);
      xmlWriter.Formatting = Formatting.Indented;
      xmlWriter.Indentation = 2;

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";
      Employee e1 = new Employee();
      e1.Name = "Pat";
      myGroup.Employees=new Employee[]{e1};

      // Write the root element.
      xmlWriter.WriteStartElement("root");

      // Serialize the class.
      mySerializer.Serialize(xmlWriter, myGroup);

      // Close the root tag.
      xmlWriter.WriteEndElement();

      // Close the XmlWriter.
      xmlWriter.Close();

      // Close the TextWriter.
      writer.Close();
   }

   public void SerializeOverride(string filename)
   {
      // Create an instance of the XmlSerializer class that
      // uses a SoapAttributeOverrides object.

      XmlSerializer mySerializer =  CreateOverrideSerializer();

      // Writing the file requires a TextWriter.
      TextWriter writer = new StreamWriter(filename);

      // Create an XML text writer.
      XmlTextWriter xmlWriter = new XmlTextWriter(writer);
      xmlWriter.Formatting = Formatting.Indented;
      xmlWriter.Indentation = 2;

      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";
      Employee e1 = new Employee();
      e1.Name = "Pat";
      myGroup.Employees=new Employee[]{e1};

      // Write the root element.
      xmlWriter.WriteStartElement("root");

      // Serialize the class.
      mySerializer.Serialize(xmlWriter, myGroup);

      // Close the root tag.
      xmlWriter.WriteEndElement();

      // Close the XmlWriter.
      xmlWriter.Close();

      // Close the TextWriter.
      writer.Close();
   }

   private XmlSerializer CreateOverrideSerializer()
   {
      // Create and return an XmlSerializer instance used to
      // override and create SOAP messages.
      SoapAttributeOverrides mySoapAttributeOverrides =
          new SoapAttributeOverrides();
      SoapAttributes soapAtts = new SoapAttributes();

      // Override the SoapTypeAttribute.
      SoapTypeAttribute soapType = new SoapTypeAttribute();
      soapType.TypeName = "Team";
      soapType.IncludeInSchema = false;
      soapType.Namespace = "http://www.microsoft.com";
      soapAtts.SoapType = soapType;

      mySoapAttributeOverrides.Add(typeof(Group),soapAtts);

      // Create an XmlTypeMapping that is used to create an instance
      // of the XmlSerializer. Then return the XmlSerializer object.
      XmlTypeMapping myMapping = (new SoapReflectionImporter(
      mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));

      XmlSerializer ser = new XmlSerializer(myMapping);
      return ser;
   }

   public void DeserializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class.
      XmlSerializer mySerializer =  CreateOverrideSerializer();

      // Reading the file requires a TextReader.
      TextReader reader = new StreamReader(filename);

      // Create an XML text reader.
      XmlTextReader xmlReader = new XmlTextReader(reader);
      xmlReader.ReadStartElement();

      // Deserialize and cast the object.
      Group myGroup = (Group) mySerializer.Deserialize(xmlReader);
      xmlReader.ReadEndElement();
      Console.WriteLine("The GroupName is " + myGroup.GroupName);
      Console.WriteLine("Look at the SoapType.xml and SoapType2.xml " +
        "files for the generated XML.");

      // Close the readers.
      xmlReader.Close();
      reader.Close();
   }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

' The SoapType is overridden when the
' SerializeOverride  method is called.
<SoapType("SoapGroupType", "http://www.cohowinery.com")> _
Public class Group
   Public GroupName As String
   Public Employees() As Employee
End Class

<SoapType("EmployeeType")> _
Public Class Employee
   Public Name As String
End Class
   
Public class Run
   Public Shared Sub Main()
      Dim test As Run = New Run()
      test.SerializeOriginal("SoapType.xml")
      test.SerializeOverride("SoapType2.xml")
      test.DeserializeObject("SoapType2.xml")
   End Sub

   Public Sub SerializeOriginal(filename As String )
      ' Create an instance of the XmlSerializer class that
      ' can be used for serializing as a SOAP message.
     Dim mapp  As XmlTypeMapping = _
      (New SoapReflectionImporter()).ImportTypeMapping(GetType(Group))
      Dim mySerializer As XmlSerializer =  _
      New XmlSerializer(mapp)
      
      ' Writing the file requires a TextWriter.
      Dim writer As TextWriter = New StreamWriter(filename)

      ' Create an XML text writer.
      Dim xmlWriter As XmlTextWriter = New XmlTextWriter(writer)
      xmlWriter.Formatting = Formatting.Indented
      xmlWriter.Indentation = 2

      ' Create an instance of the class that will be serialized.
      Dim myGroup As Group = New Group()

      ' Set the object properties.
      myGroup.GroupName = ".NET"
      Dim e1 As Employee = New Employee()
      e1.Name = "Pat"
      myGroup.Employees=New Employee(){e1}

      ' Write the root element.
      xmlWriter.WriteStartElement("root")

      ' Serialize the class.
      mySerializer.Serialize(xmlWriter, myGroup)

      ' Close the root tag.
      xmlWriter.WriteEndElement()

      ' Close the XmlWriter.
      xmlWriter.Close()

      ' Close the TextWriter.
      writer.Close()
   End Sub

   Public Sub SerializeOverride(filename As string )
   
      ' Create an instance of the XmlSerializer class that
      ' uses a SoapAttributeOverrides object.
      Dim mySerializer As XmlSerializer =  CreateOverrideSerializer()

      ' Writing the file requires a TextWriter.
      Dim writer As TextWriter = New StreamWriter(filename)

      ' Create an XML text writer.
      Dim xmlWriter As XmlTextWriter = New XmlTextWriter(writer)
      xmlWriter.Formatting = Formatting.Indented
      xmlWriter.Indentation = 2

      ' Create an instance of the class that will be serialized.
      Dim myGroup As Group = New Group()

      ' Set the object properties.
      myGroup.GroupName = ".NET"
      Dim e1 As Employee = New Employee()
      e1.Name = "Pat"
      myGroup.Employees = New Employee(){e1}

      ' Write the root element.
      xmlWriter.WriteStartElement("root")

      ' Serialize the class.
      mySerializer.Serialize(xmlWriter, myGroup)

      ' Close the root tag.
      xmlWriter.WriteEndElement()

      ' Close the XmlWriter.
      xmlWriter.Close()

      ' Close the TextWriter.
      writer.Close()
   End Sub

   Private Function CreateOverrideSerializer() As XmlSerializer 
      ' Create and return an XmlSerializer instance used to
      ' override and create SOAP messages.
      Dim mySoapAttributeOverrides As SoapAttributeOverrides = _
        New SoapAttributeOverrides()
      Dim soapAtts As SoapAttributes = New SoapAttributes()

      ' Override the SoapTypeAttribute.
      Dim soapType As SoapTypeAttribute = New SoapTypeAttribute()
      soapType.TypeName = "Team"
      soapType.IncludeInSchema = false
      soapType.Namespace = "http://www.microsoft.com"
      soapAtts.SoapType = soapType
      
      mySoapAttributeOverrides.Add(GetType(Group),soapAtts)

      ' Create an XmlTypeMapping that is used to create an instance 
      ' of the XmlSerializer. Then return the XmlSerializer object.
      Dim myMapping As XmlTypeMapping = (New SoapReflectionImporter( _
      mySoapAttributeOverrides)).ImportTypeMapping(GetType(Group))
    
      Dim  ser As XmlSerializer = New XmlSerializer(myMapping)
      
      return ser
   End Function

   Public Sub DeserializeObject(filename As String)
      ' Create an instance of the XmlSerializer class.
      Dim mySerializer As XmlSerializer =  CreateOverrideSerializer()

      ' Reading the file requires a TextReader.
      Dim reader As TextReader = New StreamReader(filename)

      ' Create an XML text reader.
      Dim xmlReader As XmlTextReader = New XmlTextReader(reader)
      xmlReader.ReadStartElement()

      ' Deserialize and cast the object.
      Dim myGroup As Group = CType(mySerializer.Deserialize(xmlReader), Group)
      xmlReader.ReadEndElement()
      Console.WriteLine("The GroupName is " + myGroup.GroupName)
      Console.WriteLine("Look at the SoapType.xml and SoapType2.xml " + _
        "files for the generated XML.")

      ' Close the readers.
      xmlReader.Close()
      reader.Close()
   End Sub
End Class

설명

클래스는 SoapTypeAttribute 개체를 인코딩된 SOAP XML로 직렬화하거나 역직렬화하는 방법을 XmlSerializer 제어하는 특성 패밀리에 속합니다. 결과 XML은 WORLD Wide Web 컨소시엄 문서 SOAP(Simple Object Access Protocol) 1.1의 섹션 5를 준수합니다. 유사한 특성의 전체 목록은 인코딩된 SOAP Serialization을 제어하는 특성을 참조하세요.

개체를 인코딩된 SOAP 메시지로 serialize하려면 클래스의 SoapReflectionImporter 메서드로 ImportTypeMapping 만든 항목을 사용하여 XmlTypeMapping 생성 XmlSerializer 합니다.

클래스 SoapTypeAttribute 선언에만 적용할 수 있습니다.

이 속성은 IncludeInSchema 생성된 XML 스트림의 XML 스키마 문서(.xsd)에 결과 XML 요소 형식이 포함되는지 여부를 결정합니다. 스키마를 보려면 클래스를 DLL 파일로 컴파일합니다. 결과 파일을 XML 스키마 정의 도구(Xsd.exe)에 인수로 전달합니다. 이 도구는 클래스가 클래스 인스턴스에 의해 serialize될 때 생성된 XML 스트림에 대한 XML 스키마를 XmlSerializer 생성합니다.

다른 네임스페이스를 설정하면 Xsd.exe 클래스가 serialize될 때 생성된 XML 스트림에 대해 다른 스키마(.xsd) 파일을 작성합니다.

생성자

SoapTypeAttribute()

SoapTypeAttribute 클래스의 새 인스턴스를 초기화합니다.

SoapTypeAttribute(String)

SoapTypeAttribute 클래스의 새 인스턴스를 초기화하고 XML 형식의 이름을 지정합니다.

SoapTypeAttribute(String, String)

SoapTypeAttribute 클래스의 새 인스턴스를 초기화하고 형식의 이름과 XML 네임스페이스를 지정합니다.

속성

IncludeInSchema

SOAP 인코딩된 XML 스키마 문서에 형식을 포함시킬지 여부를 나타내는 값을 가져오거나 설정합니다.

Namespace

XML 형식의 네임스페이스를 가져오거나 설정합니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)
TypeName

XML 형식의 이름을 가져오거나 설정합니다.

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상