2

我有一个在 WCF 中用于发送 SOAP 响应的数据类型。它看起来像这样:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <start-call-recording-response xmlns="http://foobar">
         <response>true</response>
      </start-call-recording-response>
   </s:Body>
</s:Envelope>

问题是命名空间 ( http://foobar) 没有出现在元素中。也就是说,除非我将 XmlElementAttibute 的命名空间更改为与父类的 XmlRootAttribute 的命名空间不同的东西。这是开始呼叫记录响应的类:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.18033")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(TypeName = "StartcallrecordingresponseType")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://foobar", ElementName = "start-call-recording-responseType")]
public partial class StartcallrecordingresponseType
{
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://foobar")]
    private bool responseField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://foobar", ElementName = "response", IsNullable = false)]
    public bool Response
    {
        get
        {
            return this.responseField;
        }
        set
        {
            this.responseField = value;
        }
    }
}

如果我将 Response 上方的 XmlElementAttribute 的命名空间更改为包含类的命名空间以外的其他内容,它将出现在 SOAP 信封的 . 如果它们相同,则不会出现。尝试了 XmlTypeAttributes、XmlRootAttributes 和 XmlElementAttributes 的许多变体。

4

1 回答 1

1

这是对的。请参阅命名空间规范

默认命名空间声明的范围从它出现的开始标签的开头延伸到相应的结束标签的末尾,不包括任何内部默认命名空间声明的范围。在空标签的情况下,范围是标签本身。

所以 response 元素从它的 start-call-recording-response 父级继承了 foobar 命名空间。

于 2013-03-22T23:30:15.023 回答