2012-05-03 24 views
1

我有被deserialising多態對象的數組一個WCF web服務的問題。服務器端不是WCF,但我從WSDL創建了存根。在WSDL中的重要部分是與WCF deserialising含態對象SOAP數組問題

<complexType name="NodeList"> 
    <sequence> 
     <element name="data" type="cmtypes:Node" minOccurs="0" maxOccurs="unbounded" nillable="true"/> 
    </sequence> 
</complexType> 

<complexType name="Device"> 
    <sequence> 
     <element name="uniqueKey" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/> 
     <element name="revision" type="xsd:string" minOccurs="1" maxOccurs="1"/> 
     [...} 
    </sequence> 
</complexType> 

<complexType name="Node"> 
    <complexContent> 
     <extension base="cmtypes:Device"> 
      <sequence> 
       <element name="cmdaemonUrl" type="xsd:string" minOccurs="1" maxOccurs="1"/> 
       <element name="networks" type="cmtypes:NetworkInterfaceList" minOccurs="0" maxOccurs="1" nillable="true"/> 
       [...] 
      </sequence> 
     </extension> 
    </complexContent> 
</complexType> 

<complexType name="MasterNode"> 
    <complexContent> 
     <extension base="cmtypes:Node"> 
      <sequence> 
      </sequence> 
     </extension> 
    </complexContent> 
</complexType> 

VS創建的列表中的以下類型:

[System.Xml.Serialization.SoapIncludeAttribute(typeof(MasterNode))] 
[System.Xml.Serialization.SoapIncludeAttribute(typeof(SlaveNode))] 
[System.Xml.Serialization.SoapIncludeAttribute(typeof(VirtualSMPNode))] 
[System.Xml.Serialization.SoapIncludeAttribute(typeof(VirtualNode))] 
[System.Xml.Serialization.SoapIncludeAttribute(typeof(PhysicalNode))] 
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace="http://www.brightcomputing.com/cmtypes.xsd")] 
public partial class Node : Device { 

    private string cmdaemonUrlField; 

    [...] 
} 

然而,如果收到含有像

主節點的消息
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cmtypes="http://www.brightcomputing.com/cmtypes.xsd" xmlns:cmdevice="http://www.brightcomputing.com/cmdevice.wsdl"> 
    <s:Header xmlns:s="http://www.w3.org/2003/05/soap-envelope"></s:Header> 
    <SOAP-ENV:Body> 
     <cmdevice:getNodesResponse SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> 
      <nodes xsi:type="cmtypes:NodeList" xmlns=""> 
       <data xsi:type="cmtypes:MasterNode"> 
        <uniqueKey xsi:type="xsd:unsignedLong">38654705666</uniqueKey> 
        <revision xsi:type="xsd:string"></revision> 
        <modified xsi:type="xsd:boolean">false</modified> 
        <toBeRemoved xsi:type="xsd:boolean">false</toBeRemoved> 
[...] 

的整個東西爆炸System.ServiceModel.CommunicationException說:「錯誤反序列化操作'getNodes'回覆消息的主體」。和「對象不能存儲在這種類型的數組中」。在內部的例外。爲什麼?我能做些什麼來解決這個問題(存根)?

我完全是由於非常有限的WCF/SOAP知識不知道,所以任何幫助表示讚賞。

最好的問候, 克里斯托夫

編輯:這可能是相關的,響應實際上包含不同的,多態類型的「數據」元素,即cmtypes:MasterNodecmtypes:PhysicalNode

編輯:難道說存根和消息不會在一起嗎?據我所知,存根期望一個data屬性,它是一個數組:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.SoapTypeAttribute(Namespace="http://www.brightcomputing.com/cmtypes.xsd")] 
public partial class NodeList : object, System.ComponentModel.INotifyPropertyChanged { 

    private Node[] dataField; 

    /// <remarks/> 
    [System.Xml.Serialization.SoapElementAttribute(IsNullable=true)] 
    public Node[] data { 
     get { 
      return this.dataField; 
     } 
     set { 
      this.dataField = value; 
      this.RaisePropertyChanged("data"); 
     } 
    } 

    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; 

    protected void RaisePropertyChanged(string propertyName) { 
     System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged; 
     if ((propertyChanged != null)) { 
      propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

然而,在我的回答我得到一個NodeList直接含有data元件,其實際上是節點或從節點衍生的序列:

<cmdevice:getNodesResponse SOAP-ENV:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> 
    <nodes xsi:type="cmtypes:NodeList" xmlns=""> 
     <data xsi:type="cmtypes:MasterNode"> 
      <uniqueKey xsi:type="xsd:unsignedLong">38654705666</uniqueKey> 

      [...] 
     </data> 
     <data xsi:type="cmtypes:PhysicalNode"> 
      <uniqueKey xsi:type="xsd:unsignedLong">38654705669</uniqueKey> 
      [...] 
     </data> 
    [...] 

你認爲我可以通過在WCF中注入行爲來解決這個問題嗎?我最大的問題是,我絕對沒有可能性chaning服務器端的...

+0

哪裏是cmtypes一個定義:NetworkInterfaceList? –

+0

它在WSDL中。爲了簡潔起見,我省略了它(還有很多其他的東西),但是如果它很重要,我可以發佈它。 – Christoph

+0

請發佈整個wsdl(包括引用模式)和整個返回soap。如果它是保密的,你也可以郵寄給我。 –

回答

0

排除這將是困難的。我想嘗試的一件事是使用XmlSerializer來查看它是否可以反序列化,然後開始減少消息,直到獲得違規類型。