2013-02-11 15 views
6

Hizmetim diğer yöntemler için çalışıyor ancak daha karmaşık bir koleksiyona sahip bir yöntemi çağırmaya çalıştığımda hatadan (Hizmet İzleyicisi Görüntüleyicisi)WCF hatası 'Parametre serileştirilmeye çalışılırken bir hata oluştu ...'

'http://tempuri.org/:GetDataEventSetResult parametresini seri hale getirmeye çalışırken bir hata oluştu. InnerException iletisinin veri sözleşmesi adı olan 'Type' MimosaServerLib.DAInt 'idi' DAInt: http://schemas.datacontract.org/2004/07/MimosaServerLib 'beklenmiyor ...'

Aynı hataya sahip soruların cevapları, sınıf tanımını değiştirmek için değiştirmeyi de içeriyor. off 'ProxyCreationEnabled' ile çalıştığım sınıflar (DataEventSet, DAInt), verilmiş xsd aracı kullanılarak otomatik olarak oluşturulan bir dosyadan geliyor. yani onu değiştirmemeliydim.

Öyle gibi maruz DataEventSet nesne oluşturmak:

private DataEventSet CreateDataEventSet() 
    { 
     DataEventSet aDataEventSet = new DataEventSet(); 
     DataEvent[] dataEvents = new DataEvent[2]; 
     DAInt aDAInt = new DAInt(); 
      aDAInt.id = 100100100; 
      aDAInt.value = 1; 
      dataEvents[0] = aDAInt; 
     DADataSeq aDADataSeq = new DADataSeq(); 
      aDADataSeq.id = 200100100; 
      double[] vals = new double[2]; 
       vals[0] = 5; 
       vals[1] = 44; 
      aDADataSeq.values = vals; 
      double[] vals2 = new double[2]; 
       vals2[0] = 1; 
       vals2[1] = 1; 
      aDADataSeq.xAxisDeltas = vals2; 
      aDADataSeq.xAxisStart = 0; 
      dataEvents[1] = aDADataSeq; 
     aDataEventSet.id = 0; 
     Site aSite = new Site(); 
      aSite.category = SITE_CATEGORY.SITE_SPECIFIC; 
     aDataEventSet.site = aSite; 
     OsacbmTime aTime = new OsacbmTime(); 
      aTime.tick_time = 12313246; 
      aTime.time = "2007-09-20T14:46:04.123"; 
      aTime.time_type = OsacbmTimeType.OSACBM_TIME_MIMOSA; 
     aDataEventSet.time = aTime; 
     aDataEventSet.dataEvents = dataEvents; 

     return aDataEventSet; 
    } 

Edit: DataEventSet

//This source code was auto-generated by xsd 

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.mimosa.org/OSACBMV3-1l")] 
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.mimosa.org/OSACBMV3-1l", IsNullable=false)] 
public partial class DataEventSet { 

private bool alertStatusField; 

private bool alertStatusFieldSpecified; 

private DataEvent[] dataEventsField; 

private ulong idField; 

private Site siteField; 

private OsacbmTime timeField; 

/// <remarks/> 
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
public bool alertStatus { 
    get { 
     return this.alertStatusField; 
    } 
    set { 
     this.alertStatusField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.XmlIgnoreAttribute()] 
public bool alertStatusSpecified { 
    get { 
     return this.alertStatusFieldSpecified; 
    } 
    set { 
     this.alertStatusFieldSpecified = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.XmlElementAttribute("dataEvents", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
public DataEvent[] dataEvents { 
    get { 
     return this.dataEventsField; 
    } 
    set { 
     this.dataEventsField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
public ulong id { 
    get { 
     return this.idField; 
    } 
    set { 
     this.idField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
public Site site { 
    get { 
     return this.siteField; 
    } 
    set { 
     this.siteField = value; 
    } 
} 

/// <remarks/> 
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] 
public OsacbmTime time { 
    get { 
     return this.timeField; 
    } 
    set { 
     this.timeField = value; 
    } 
} 

}

cevap

6

sınıf tanımını Sana ihtiyacım olacağını düşünüyorum KnownType(typeof(DAInt)) özniteliğini DataEventSet sınıfına eklemek, çünkü bunu polimorfik bir şekilde kullanıyorsunuzdur. Değişikliklerimi genellikle oluşturulan kodun içine DataEventSet.xsd.nongenerated.cs gibi bir şey denilen yeni bir dosyaya eklerim. Bu nedenle oluşturulan kod, sınıfları kısmi sınıflar olarak oluşturur. Bu işe yaramazsa

[KnownType(typeof(DAInt))] 
public partial class DataEventSet { 
} 

, o zaman her zaman yerine XmlSerializer kullanmaya sözleşme değiştirmeyi deneyebilirsiniz:

İçinde DataEventSet.xsd.nongenerated.cs, böyle bir şey olur DataContractSerializer. Bu iyi çalışır çünkü xsd.exe tarafından oluşturulan Xml öznitelikleri kullanır.

Çalışma zamanının, hizmet sözleşmesine XmlSerializerFormatter özniteliğini ekleyerek XmlSerializer'ı kullanmasını belirtebilirsiniz.

+0

Teşekkürler! Şimdi WCF Test Client'ta çalışıyor. Ancak, bir dış İstemci ile hizmete erişmeye çalıştığımda, bir 'NetDispatcherFaultException' alıyorum: "http://tempuri.org/:GetDataEventSetResult. InnerException iletisi, 'Satır 1 konumunda 898 hatasıydı. Öğe' http: // şemaları .datacontract.org/2004/07/MimosaServerLib: DataEvent ', adıyla eşleşen bir türden veri içerir. " – Jimmy

+0

Çözüldü: Servis referansını güncellemek için gerekli lol. – Jimmy

+0

KnownType() özniteliği mi kullanıyordu? –

İlgili konular