2013-03-22 60 views
2

我有一个数据类型,我在WCF中用于​​发送SOAP响应。它看起来像这样:命名空间不附加到WCF中的bool,除非与类的命名空间不同

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

如果我改变上述响应比包含类的命名空间的东西XmlElementAttribute的命名空间,它会出现在SOAP信封的。如果它们相同,则不会出现。尝试了XmlTypeAttributes,XmlRootAttributes和XmlElementAttributes的许多变体。

回答

1

这是正确的。看到一个默认命名空间声明的namespace spec

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

因此,响应元素从其开始呼叫记录响应父节点继承foobar名称空间。

+0

这很有道理。谢谢! – ColonelGibberish 2013-03-23 18:04:51

+0

那你能接受答案吗? – flup 2013-03-23 20:26:30

+0

已接受。谢谢。 – ColonelGibberish 2013-04-03 19:47:28

相关问题