WCF Rest:DataContractSerializer - 序列化名称中包含冒号的对象

时间:2013-03-22 10:52:37

标签: xml wcf rest post serialization

嗨,我需要从我的WCF / REST获取XML Custom,但我的属性名称没有按照我的意愿序列化,因为它包含一个冒号。

我的DataContract错误响应

[DataContract(Namespace = "xxxx:xxxx:rest", Name = "hs:rest")]                 
public class ErrorResult
{
 [DataMember(Order = 0, Name = "status")]
    string Status
    {
        get
        {
            return "ERROR(5698)";
        }
        set { }
    }
    [DataMember(Order = 1, Name = "reason")]
    public string Reason { get; set; }
    [DataMember(Order = 2, Name = "extendedMessage")]
    public string ExtendedMessage { get { return string.Empty; } set { } }
    [DataMember(Order = 3, Name = "result")]
    public string Result { get { return string.Empty; } set { } }
    [DataMember(Order = 4, Name = "type")]
    public string Type { get { return string.Empty; } set { } }
    [...]
}

MY Serializer

public string XmlTranslation(ErrorResult error)
    {

        using (var memoryStream = new MemoryStream())
        {
            using (var reader = new StreamReader(memoryStream))
            {
                var serializer = new DataContractSerializer(error.GetType());
                serializer.WriteObject(memoryStream, error);
                memoryStream.Position = 0;
                return reader.ReadToEnd();
            }
        }    

使用这些方法并分析与fiddler的网络通信,结果如下:

请求:(不重要)

<?xml version="1.0" encoding="UTF-8"?><rest xmlns="xxxx:xxxx:rest" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance ">
<type>date</type> 
<domain>test.it</domain>
<date>2009-03-13</date>
<page>1</page>
<reportType>daily</reportType>
<actionName>store</actionName>
</rest>

响应:

<hs_x003A_rest xmlns="xxxx:xxxx:rest" xmlns:i="http://www.w3.org/2001/XMLSchema-
instance">
<status>ERROR(5698)</status>
<reason>InternalError(1011)</reason>
<extendedMessage/>
<result/>
<type/>
</hs_x003A_rest>

我得到一个像“hs_x003A_rest”的名字,但我得到“hs:rest” 你有什么建议吗?提前感谢您的回答

0 个答案:

没有答案