SoapElementAttribute 클래스

정의

XmlSerializer에 의해 공용 멤버 값이 인코딩된 SOAP XML 요소로 serialize되도록 지정합니다.

public ref class SoapElementAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue)]
public class SoapElementAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue)>]
type SoapElementAttribute = class
    inherit Attribute
Public Class SoapElementAttribute
Inherits Attribute
상속
SoapElementAttribute
특성

예제

다음 예제에서는 라는 클래스의 인스턴스를 serialize Transportation 라는 필드가 있는 Vehicle합니다. SoapElementAttribute 필드에 적용 됩니다. 필드도 serialize 될 때 XML 요소 이름은 "Vehicle" 대신 "바퀴"입니다. SerializeOverride 메서드를 만듭니다를 SoapElementAttribute 설정 및는 SoapElement 의 속성을 SoapAttributesSoapElementAttribute. SoapAttributes 에 추가 되는 SoapAttributeOverrides 만드는 데 사용 되는 XmlTypeMapping합니다. XmlSerializer 로 생성 된를 XmlTypeMapping의 인스턴스를 Transportation 클래스 다시 serialize 됩니다. 때문에 SoapElementAttribute 는 serialization을 재정의 하는 데, 생성 된 XML 요소 이름은 이제 "바퀴" 대신 "Truck".

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

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Collections;
using namespace System::Xml;
using namespace System::Text;
public ref class Thing
{
public:

   [SoapElement(IsNullable=true)]
   String^ ThingName;
};

public ref class Transportation
{
public:

   // The SoapElementAttribute specifies that the
   // generated XML element name will be S"Wheels"
   // instead of S"Vehicle".

   [SoapElement("Wheels")]
   String^ Vehicle;

   [SoapElement(DataType="dateTime")]
   DateTime CreationDate;

   [SoapElement(IsNullable=true)]
   Thing^ thing;
};

public ref class Test
{
public:

   // Return an XmlSerializer used for overriding.
   XmlSerializer^ CreateSoapOverrider()
   {
      // Create the SoapAttributes and SoapAttributeOverrides objects.
      SoapAttributes^ soapAttrs = gcnew SoapAttributes;
      SoapAttributeOverrides^ soapOverrides = gcnew SoapAttributeOverrides;

      // Create an SoapElementAttribute to the Vehicles property.
      SoapElementAttribute^ soapElement1 = gcnew SoapElementAttribute( "Truck" );

      // Set the SoapElement to the Object*.
      soapAttrs->SoapElement = soapElement1;

      // Add the SoapAttributes to the SoapAttributeOverrides,specifying the member to.
      soapOverrides->Add( Transportation::typeid, "Vehicle", soapAttrs );

      // Create the XmlSerializer, and return it.
      XmlTypeMapping^ myTypeMapping = (gcnew SoapReflectionImporter( soapOverrides ))->ImportTypeMapping( Transportation::typeid );
      return gcnew XmlSerializer( myTypeMapping );
   }

   void SerializeOverride( String^ filename )
   {
      // Create an XmlSerializer instance.
      XmlSerializer^ ser = CreateSoapOverrider();

      // Create the Object* and serialize it.
      Transportation^ myTransportation = gcnew Transportation;
      myTransportation->Vehicle = "MyCar";
      myTransportation->CreationDate = DateTime::Now;
      myTransportation->thing = gcnew Thing;
      XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
      writer->Formatting = Formatting::Indented;
      writer->WriteStartElement( "wrapper" );
      ser->Serialize( writer, myTransportation );
      writer->WriteEndElement();
      writer->Close();
   }

   void SerializeObject( String^ filename )
   {
      // Create an XmlSerializer instance.
      XmlSerializer^ ser = gcnew XmlSerializer( Transportation::typeid );
      Transportation^ myTransportation = gcnew Transportation;
      myTransportation->Vehicle = "MyCar";
      myTransportation->CreationDate = DateTime::Now;
      myTransportation->thing = gcnew Thing;
      XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
      writer->Formatting = Formatting::Indented;
      writer->WriteStartElement( "wrapper" );
      ser->Serialize( writer, myTransportation );
      writer->WriteEndElement();
      writer->Close();
   }
};

int main()
{
   Test^ t = gcnew Test;
   t->SerializeObject( "SoapElementOriginal.xml" );
   t->SerializeOverride( "SoapElementOverride.xml" );
   Console::WriteLine( "Finished writing two XML files." );
}
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
using System.Text;
public class Transportation
{
   // The SoapElementAttribute specifies that the
   // generated XML element name will be "Wheels"
   // instead of "Vehicle".
   [SoapElement("Wheels")]
   public string Vehicle;
   [SoapElement(DataType = "dateTime")]
   public DateTime CreationDate;
   [SoapElement(IsNullable = true)]
   public Thing thing;
}

public class Thing{
   [SoapElement(IsNullable=true)] public string ThingName;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("SoapElementOriginal.xml");
      t.SerializeOverride("SoapElementOverride.xml");
      Console.WriteLine("Finished writing two XML files.");
   }

   // Return an XmlSerializer used for overriding.
   public XmlSerializer CreateSoapOverrider()
   {
      // Create the SoapAttributes and SoapAttributeOverrides objects.
      SoapAttributes soapAttrs = new SoapAttributes();

      SoapAttributeOverrides soapOverrides =
      new SoapAttributeOverrides();

      /* Create an SoapElementAttribute to override
      the Vehicles property. */
      SoapElementAttribute soapElement1 =
      new SoapElementAttribute("Truck");
      // Set the SoapElement to the object.
      soapAttrs.SoapElement= soapElement1;

      /* Add the SoapAttributes to the SoapAttributeOverrides,
      specifying the member to override. */
      soapOverrides.Add(typeof(Transportation), "Vehicle", soapAttrs);

      // Create the XmlSerializer, and return it.
      XmlTypeMapping myTypeMapping = (new SoapReflectionImporter
      (soapOverrides)).ImportTypeMapping(typeof(Transportation));
      return new XmlSerializer(myTypeMapping);
   }

   public void SerializeOverride(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer ser = CreateSoapOverrider();

      // Create the object and serialize it.
      Transportation myTransportation =
      new Transportation();

      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate=DateTime.Now;
      myTransportation.thing = new Thing();

      XmlTextWriter writer =
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
   public void SerializeObject(string filename){
      // Create an XmlSerializer instance.
      XmlSerializer ser = new XmlSerializer(typeof(Transportation));
      Transportation myTransportation =
      new Transportation();
      myTransportation.Vehicle = "MyCar";
      myTransportation.CreationDate = DateTime.Now;
      myTransportation.thing = new Thing();
      XmlTextWriter writer =
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      ser.Serialize(writer, myTransportation);
      writer.WriteEndElement();
      writer.Close();
   }
}
Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections
Imports System.Xml
Imports System.Text

Public Class Transportation
   ' The SoapElementAttribute specifies that the
   ' generated XML element name will be "Wheels"
   ' instead of "Vehicle".
   <SoapElement("Wheels")> Public Vehicle As String 
   <SoapElement(DataType:= "dateTime")> _
   public CreationDate As DateTime    
   <SoapElement(IsNullable:= true)> _
   public thing As Thing
End Class

Public Class Thing
   <SoapElement(IsNullable:=true)> public ThingName As string 
End Class

Public Class Test

   Shared Sub Main()
      Dim t As Test = New Test()
      t.SerializeObject("SoapElementOriginalVb.xml")
      t.SerializeOverride("SoapElementOverrideVb.xml")
      Console.WriteLine("Finished writing two XML files.")
   End Sub

   ' Return an XmlSerializer used for overriding.
   Public Function CreateSoapOverrider() As XmlSerializer 
      ' Create the SoapAttributes and SoapAttributeOverrides objects.
      Dim soapAttrs As SoapAttributes = New SoapAttributes()

      Dim soapOverrides As SoapAttributeOverrides = _
      New SoapAttributeOverrides()
            
      ' Create a SoapElementAttribute to override 
      ' the Vehicles property. 
      Dim soapElement1 As SoapElementAttribute = _
      New SoapElementAttribute("Truck")
      ' Set the SoapElement to the object.
      soapAttrs.SoapElement= soapElement1

      ' Add the SoapAttributes to the SoapAttributeOverrides,
      ' specifying the member to override. 
      soapOverrides.Add(GetType(Transportation), "Vehicle", soapAttrs)
      
      ' Create the XmlSerializer, and return it.
      Dim myTypeMapping As XmlTypeMapping = (New _
      SoapReflectionImporter (soapOverrides)).ImportTypeMapping _
      (GetType(Transportation))
      return New XmlSerializer(myTypeMapping)
   End Function

   Public Sub SerializeOverride(filename As String)
      ' Create an XmlSerializer instance.
      Dim ser As XmlSerializer = CreateSoapOverrider()

      ' Create the object and serialize it.
      Dim myTransportation As Transportation = _
      New Transportation()

      myTransportation.Vehicle = "MyCar"
      myTransportation.CreationDate = DateTime.Now
      myTransportation.thing= new Thing()
      
      Dim writer As XmlTextWriter = _
      New XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ser.Serialize(writer, myTransportation)
      writer.WriteEndElement()
      writer.Close()
   End Sub

   Public Sub SerializeObject(filename As String)
      ' Create an XmlSerializer instance.
      Dim ser As XmlSerializer = _
      New XmlSerializer(GetType(Transportation))
      
      Dim myTransportation As Transportation = _
      New Transportation()
      
      myTransportation.Vehicle = "MyCar"
      myTransportation.CreationDate=DateTime.Now
      myTransportation.thing= new Thing()

      Dim writer As XmlTextWriter = _
      new XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ser.Serialize(writer, myTransportation)
      writer.WriteEndElement()
      writer.Close()
   End Sub
End Class

설명

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

개체를 인코딩된 SOAP 메시지로 직렬화하려면 클래스 메서드 SoapReflectionImporterImportTypeMapping 사용하여 만든 항목을 생성 XmlSerializer XmlTypeMapping 해야 합니다.

SoapElementAttribute 공용 필드에 적용하여 인코딩된 SOAP XML 요소로 필드를 직렬화하도록 지시 XmlSerializer 합니다.

특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

생성자

SoapElementAttribute()

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

SoapElementAttribute(String)

SoapElementAttribute 클래스의 새 인스턴스를 초기화하고 XML 요소의 이름을 지정합니다.

속성

DataType

생성된 XML 요소의 XSD(XML Schema Definition language) 데이터 형식을 가져오거나 설정합니다.

ElementName

생성된 XML 요소의 이름을 가져오거나 설정합니다.

IsNullable

XmlSerializerxsi:null 특성이 "1"로 설정된 멤버를 serialize해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

TypeId

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

(다음에서 상속됨 Attribute)

메서드

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)

적용 대상