webwires
webwires

Reputation: 1907

default xmlns serializing as blank on string object

I'm using a Serializable Dictionary code object. For some reason when I serialize the object in a SOAP web service the the string object serializes with a blank namespace. I cannot get it to go away.:

 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();
        }

I've tried using the XmlSerializerNamespaces on the XmlSerializer as well as the XmlAttributeOverrides but I cannot get it to go away. I keep getting

<?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>

Upvotes: 0

Views: 479

Answers (2)

John Saunders
John Saunders

Reputation: 161773

Use the WriteStartElement(String, String) overload.

Upvotes: 0

Martin v. L&#246;wis
Martin v. L&#246;wis

Reputation: 127447

Using the XmlSerializer constructor that expects a default namespace might fix the problem.

Upvotes: 2

Related Questions