默认xmlns在字符串对象上序列化为空白

时间:2009-08-31 20:56:35

标签: c# .net xml xml-serialization

我正在使用Serializable Dictionary代码对象。出于某种原因,当我在SOAP Web服务中序列化对象时,字符串对象使用空白名称空间进行序列化。我不能让它消失。:

 XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

        foreach (TKey key in this.Keys)
        {
            writer.WriteStartElement("item");

            writer.WriteStartElement("key");
            keySerializer.Serialize(writer, key);
            writer.WriteEndElement();

            writer.WriteStartElement("value");
            TValue value = this[key];
            valueSerializer.Serialize(writer, value, ns);
            writer.WriteEndElement();

            writer.WriteEndElement();
        }

我已尝试在XmlSerializer上使用XmlSerializerNamespaces以及XmlAttributeOverrides,但我无法让它消失。我一直在

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <GetSiteListPermissionsResponse xmlns="http://HDMenu">
   <GetSiteListPermissionsResult>
    <item>
     <key>
      <string xmlns="">http://devvm.local/second3/default.aspx</string>
     </key>
     <value>
      <string xmlns="">True</string>
     </value>
    </item>
   </GetSiteListPermissionsResult>
  </GetSiteListPermissionsResponse>
 </soap:Body>
</soap:Envelope>

2 个答案:

答案 0 :(得分:2)

使用需要默认命名空间的XmlSerializer constructor可能会解决问题。

答案 1 :(得分:0)