如何在soap序列化中摆脱前缀_x003C_?

时间:2016-10-24 19:33:30

标签: serialization soap prefix

我使用以下方法对soap包络进行序列化:

[Serializable]
class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Person person = new Person("Tom", 29);
        Person person2 = new Person("Bill", 25);
        Person[] people = new Person[] { person, person2 };

        SoapFormatter formatter = new SoapFormatter();
        using (FileStream fs = new FileStream("people.soap", FileMode.OpenOrCreate))
        {
            formatter.Serialize(fs, people);

            Console.WriteLine("Serialized");
        }

        using (FileStream fs = new FileStream("people.soap", FileMode.OpenOrCreate))
        {
            Person[] newPeople = (Person[])formatter.Deserialize(fs);

            Console.WriteLine("Deserialized");
            foreach (Person p in newPeople)
            {
                Console.WriteLine("Name: {0} --- Age: {1}", p.Name, p.Age);
            }
        }
        Console.ReadLine();
    }
}

我得到如下序列化肥皂:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENC:Array SOAP-ENC:arrayType="a1:Person[2]" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Serialization/Serialization%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<item href="#ref-3"/>
<item href="#ref-4"/>
</SOAP-ENC:Array>
<a1:Person id="ref-3" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Serialization/Serialization%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_Name_x003E_k__BackingField id="ref-5">Tom</_x003C_Name_x003E_k__BackingField>
<_x003C_Age_x003E_k__BackingField>29</_x003C_Age_x003E_k__BackingField>
</a1:Person>
<a1:Person id="ref-4" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/Serialization/Serialization%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_Name_x003E_k__BackingField id="ref-6">Bill</_x003C_Name_x003E_k__BackingField>
<_x003C_Age_x003E_k__BackingField>25</_x003C_Age_x003E_k__BackingField>
</a1:Person>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如何摆脱前缀&#34; x003C &#34;和后缀&#34; _x003E_k__BackingField&#34; 在我的领域&#34;姓名&#34;和&#34;年龄&#34;?

非常感谢您的回答

0 个答案:

没有答案