SoapAttributeAttribute Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Megadja, hogy az XmlSerializer osztálytagot kódolt SOAP-attribútumként kell szerializálnia.
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
- Öröklődés
- Attribútumok
Példák
Az alábbi példa szerializál egy osztályt, amely több olyan mezőt tartalmaz, amelyekre alkalmazva SoapAttributeAttribute van.
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
Megjegyzések
Az SoapAttributeAttribute osztály egy attribútumcsaládhoz tartozik, amely azt szabályozza, hogyan XmlSerializer szerializál vagy deszerializál egy objektumot kódolt SOAP XML-fájlként. Az eredményként kapott XML megfelel a World Wide Web Consortium dokumentum, a Simple Object Access Protocol (SOAP) 1.1 című dokumentum 5. szakaszának. A hasonló attribútumok teljes listáját a kódolt SOAP-szerializálást vezérlő attribútumok című témakörben találja.
Ha kódolt SOAP-üzenetként szeretne szerializálni egy objektumot, létre kell hoznia az XmlSerializerXmlTypeMapping osztály metódusával ImportTypeMapping létrehozott objektumot SoapReflectionImporter .
Alkalmazza a SoapAttributeAttribute mezőt egy nyilvános mezőre annak megadásához, hogy a XmlSerializer szerializálja a mezőt XML-attribútumként. A tulajdonság beállításával AttributeName megadhatja az attribútum alternatív nevét. Adja meg, DataType hogy az attribútumnak adott XML-sémadefiníciós (XSD) adattípust kell-e adni. Ha az attribútum egy adott XML-névtérhez tartozik, állítsa be a tulajdonságot Namespace .
További információ az attribútumok használatáról: Attribútumok
Note
A hosszabb helyett használhatja a szót SoapAttribute a SoapAttributeAttributekódban.
Konstruktorok
| Name | Description |
|---|---|
| SoapAttributeAttribute() |
Inicializálja a SoapAttributeAttribute osztály új példányát. |
| SoapAttributeAttribute(String) |
Inicializálja az osztály új példányát a SoapAttributeAttribute megadott érték használatával az XML-attribútum neveként. |
Tulajdonságok
| Name | Description |
|---|---|
| AttributeName |
Lekéri vagy beállítja a rendszer által XmlSerializerlétrehozott XML-attribútum nevét. |
| DataType |
Lekéri vagy beállítja a SOAP attribútum által létrehozott XML-sémadefiníciós nyelv (XSD) adattípusát XmlSerializer. |
| Namespace |
Lekéri vagy beállítja az XML-attribútum XML-névterét. |
| TypeId |
Ha származtatott osztályban implementálják, ehhez egy egyedi azonosítót Attributekap. (Öröklődés forrása Attribute) |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Olyan értéket ad vissza, amely jelzi, hogy ez a példány egyenlő-e egy adott objektummal. (Öröklődés forrása Attribute) |
| GetHashCode() |
A példány kivonatkódját adja vissza. (Öröklődés forrása Attribute) |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| IsDefaultAttribute() |
Ha egy származtatott osztályban felül van bírálva, azt jelzi, hogy a példány értéke-e a származtatott osztály alapértelmezett értéke. (Öröklődés forrása Attribute) |
| Match(Object) |
Származtatott osztály felülírásakor egy olyan értéket ad vissza, amely jelzi, hogy ez a példány egy adott objektummal egyenlő-e. (Öröklődés forrása Attribute) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |
Explicit interfész-implementációk
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Névkészletet képez le a küldési azonosítók megfelelő készletére. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Lekéri egy objektum típusadatait, amelyek a felület típusadatainak lekérésére használhatók. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Lekéri az objektumok által biztosított típusinformációs felületek számát (0 vagy 1). (Öröklődés forrása Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Hozzáférést biztosít az objektumok által közzétett tulajdonságokhoz és metódusokhoz. (Öröklődés forrása Attribute) |