SoapAttributeAttribute 클래스

정의

XmlSerializer가 클래스 멤버를 인코딩된 SOAP 특성으로 serialize하도록 지정합니다.

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

예제

다음 예제에서는 적용 되는 여러 필드를 포함 하는 클래스를 SoapAttributeAttribute 직렬화 합니다.

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

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

//using namespace System::Runtime::Remoting::Metadata;
public ref class Vehicle
{
public:
   String^ licenseNumber;
};


[SoapInclude(Vehicle::typeid)]
public ref class Group
{
public:

   [SoapAttributeAttribute(Namespace="http://www.cpandl.com")]
   String^ GroupName;

   [SoapAttributeAttribute(DataType="base64Binary")]
   array<Byte>^GroupNumber;

   [SoapAttributeAttribute(DataType="date",AttributeName="CreationDate")]
   DateTime Today;

   [SoapElement(DataType="nonNegativeInteger",ElementName="PosInt")]
   String^ PostitiveInt;
   Vehicle^ GroupVehicle;
};

public ref class Run
{
public:
   void SerializeObject( String^ filename )
   {
      // Create an instance of the XmlSerializer class that
      // can generate encoded SOAP messages.
      XmlSerializer^ mySerializer = ReturnSOAPSerializer();
      Group^ myGroup = MakeGroup();

      // Writing the file requires a TextWriter.
      XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
      writer->Formatting = Formatting::Indented;
      writer->WriteStartElement( "wrapper" );

      // Serialize the class, and close the TextWriter.
      mySerializer->Serialize( writer, myGroup );
      writer->WriteEndElement();
      writer->Close();
   }


private:
   Group^ MakeGroup()
   {
      // Create an instance of the class that will be serialized.
      Group^ myGroup = gcnew Group;

      // Set the Object* properties.
      myGroup->GroupName = ".NET";
      array<Byte>^hexByte = {Convert::ToByte( 100 ),Convert::ToByte( 50 )};
      myGroup->GroupNumber = hexByte;
      DateTime myDate = DateTime(2002,5,2);
      myGroup->Today = myDate;
      myGroup->PostitiveInt = "10000";
      myGroup->GroupVehicle = gcnew Vehicle;
      myGroup->GroupVehicle->licenseNumber = "1234";
      return myGroup;
   }

public:
   void DeserializeObject( String^ filename )
   {
      // Create an instance of the XmlSerializer class that
      // can generate encoded SOAP messages.
      XmlSerializer^ mySerializer = ReturnSOAPSerializer();

      // Reading the file requires an  XmlTextReader.
      XmlTextReader^ reader = gcnew XmlTextReader( filename );
      reader->ReadStartElement( "wrapper" );

      // Deserialize and cast the Object*.
      Group^ myGroup;
      myGroup = safe_cast<Group^>(mySerializer->Deserialize( reader ));
      reader->ReadEndElement();
      reader->Close();
   }

private:
   XmlSerializer^ ReturnSOAPSerializer()
   {
      
      // Create an instance of the XmlSerializer class.
      XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid );
      return gcnew XmlSerializer( myMapping );
   }
};

int main()
{
   Run^ test = gcnew Run;
   test->SerializeObject( "SoapAtts.xml" );
   test->DeserializeObject( "SoapAtts.xml" );
}
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

[SoapInclude(typeof(Vehicle))]
public class Group
{
   [SoapAttribute (Namespace = "http://www.cpandl.com")]
   public string GroupName;

   [SoapAttribute(DataType = "base64Binary")]
   public Byte [] GroupNumber;

   [SoapAttribute(DataType = "date", AttributeName = "CreationDate")]
   public DateTime Today;
   [SoapElement(DataType = "nonNegativeInteger", ElementName = "PosInt")]
   public string PostitiveInt;

   public Vehicle GroupVehicle;
}

public class Vehicle
{
   public string licenseNumber;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("SoapAtts.xml");
      test.DeserializeObject("SoapAtts.xml");
   }
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class that
      // can generate encoded SOAP messages.
      XmlSerializer mySerializer =  ReturnSOAPSerializer();

      Group myGroup=MakeGroup();
      // Writing the file requires a TextWriter.
      XmlTextWriter writer =
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.WriteEndElement();
      writer.Close();
   }

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

      // Set the object properties.
      myGroup.GroupName = ".NET";

      Byte [] hexByte = new Byte[2]{Convert.ToByte(100),
      Convert.ToByte(50)};
      myGroup.GroupNumber = hexByte;

      DateTime myDate = new DateTime(2002,5,2);
      myGroup.Today = myDate;
      myGroup.PostitiveInt= "10000";
      myGroup.GroupVehicle = new Vehicle();
      myGroup.GroupVehicle.licenseNumber="1234";
      return myGroup;
   }   	

   public void DeserializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class that
      // can generate encoded SOAP messages.
      XmlSerializer mySerializer =  ReturnSOAPSerializer();

      // Reading the file requires an  XmlTextReader.
      XmlTextReader reader=
      new XmlTextReader(filename);
      reader.ReadStartElement("wrapper");

      // Deserialize and cast the object.
      Group myGroup;
      myGroup = (Group) mySerializer.Deserialize(reader);
      reader.ReadEndElement();
      reader.Close();
   }

   private XmlSerializer ReturnSOAPSerializer(){
      // Create an instance of the XmlSerializer class.
      XmlTypeMapping myMapping =
      (new SoapReflectionImporter().ImportTypeMapping
      (typeof(Group)));
       return new XmlSerializer(myMapping);
   }
}
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Xml.Schema

<SoapInclude(GetType(Vehicle))> _
Public Class Group

   <SoapAttribute (Namespace:= "http:'www.cpandl.com")> _
   Public GroupName As String    
   <SoapAttribute(DataType:= "base64Binary")> _
   Public GroupNumber() As  Byte 

   <SoapAttribute(DataType:= "date", AttributeName:= "CreationDate")> _
   Public Today As DateTime 
   <SoapElement(DataType:= "nonNegativeInteger", _
   ElementName:= "PosInt")> _
   Public PostitiveInt As String 

   Public GroupVehicle As Vehicle 
End Class
  
Public Class Vehicle
   Public licenseNumber As String 
End Class

Public Class Run

   Shared Sub Main()
   
      Dim test As Run = New Run()
      test.SerializeObject("SoapAtts.xml")
      test.DeserializeObject("SoapAtts.xml")
   End Sub
   
   Public Sub SerializeObject(filename As String)
   
      ' Create an instance of the XmlSerializer Class that
      ' can generate encoded SOAP messages.
      Dim mySerializer As XmlSerializer  =  ReturnSOAPSerializer()

      Dim myGroup As Group = MakeGroup()
      ' Writing the file requires a TextWriter.
      Dim writer As XmlTextWriter = _
      New XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ' Serialize the Class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup)
      writer.WriteEndElement()
      writer.Close()
   End Sub

   Private Function MakeGroup() As Group 
      ' Create an instance of the Class that will be serialized.
      Dim myGroup As Group = New Group()

      ' Set the object properties.
      myGroup.GroupName = ".NET"

      Dim hexByte() As Byte= New Byte(1){Convert.ToByte(100), _
      Convert.ToByte(50)}
      myGroup.GroupNumber = hexByte

      Dim myDate As DateTime = New DateTime(2002,5,2)
      myGroup.Today = myDate
      myGroup.PostitiveInt= "10000"
      myGroup.GroupVehicle = New Vehicle()
      myGroup.GroupVehicle.licenseNumber="1234"
      return myGroup
   End Function   	

   Public Sub DeserializeObject(filename As String)
      ' Create an instance of the XmlSerializer Class that
      ' can generate encoded SOAP messages.
      Dim mySerializer As XmlSerializer =  ReturnSOAPSerializer()

      ' Reading the file requires an  XmlTextReader.
      Dim reader As XmlTextReader = _
      New XmlTextReader(filename)
      reader.ReadStartElement("wrapper")

      ' Deserialize and cast the object.
      Dim myGroup As Group 
      myGroup = _
      CType(mySerializer.Deserialize(reader), Group)
      reader.ReadEndElement()
      reader.Close()

   End Sub
   
   private Function ReturnSOAPSerializer() As XmlSerializer 
      ' Create an instance of the XmlSerializer Class.
      Dim myMapping As XmlTypeMapping = _
      (New SoapReflectionImporter().ImportTypeMapping _
      (GetType(Group)))
       return New XmlSerializer(myMapping)
   End Function
End Class

설명

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

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

SoapAttributeAttribute 공용 필드에 적용하여 필드를 XML 특성으로 직렬화하도록 지정 XmlSerializer 합니다. 속성을 설정 AttributeName 하여 특성의 대체 이름을 지정할 수 있습니다. 특성에 DataType 특정 XSD(XML 스키마 정의 언어) 데이터 형식을 지정해야 하는 경우를 설정합니다. 특성이 특정 XML 네임스페이스에 속하는 경우 속성을 설정합니다 Namespace .

특성 사용에 대한 자세한 내용은 특성을 참조하세요.

참고

더 긴 SoapAttributeAttribute대신 코드에서 단어를 SoapAttribute 사용할 수 있습니다.

생성자

SoapAttributeAttribute()

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

SoapAttributeAttribute(String)

지정된 값을 XML 특성의 이름으로 사용하여 SoapAttributeAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

AttributeName

XmlSerializer에 의해 생성된 XML 특성의 이름을 가져오거나 설정합니다.

DataType

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

Namespace

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

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)

적용 대상

추가 정보