2010-06-01 74 views
12

可能重複:
XmlSerializer: remove unnecessary xsi and xsd namespaces從生成的XML在.NET中刪除命名空間

我生成使用XMLSerializer的一些XML並標記了屬性的類。該XML被髮送到REST Web服務。

生成下面的XML:

<?xml version="1.0" encoding="utf-8"?> 
<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <first-name>API</first-name> 
    <last-name>TestPersonDeleteMe</last-name> 
    <title>Delete me</title> 
</person> 

所有這些都很好,但我用不明白架構的東西web服務,並拋出一個500錯誤。

有沒有辦法阻止XmlSerializer將'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"'添加到標籤?

+2

這不是我的網絡服務。 – 2010-06-01 14:40:52

+0

不會改變它被打破的事實。做點什麼吧。 – 2010-06-01 14:41:26

+3

是的,我會嘗試和報告,作爲一個錯誤,一個Web服務,需要XML輸入,但無法處理XML名稱屬性被破壞。最壞的情況是它應該忽略它們。 – 2010-06-01 14:41:57

回答

21

如果使用自定義序列試試這個

XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); 
namespaces.Add(string.Empty, string.Empty); 

然後加命名空間反對你的串行器。