views:

47

answers:

1

I am trying to host a WCF service that responds to incoming requests by providing a json output stream. I have the following type

[DataContract]  
[KnownType(typeof(List<HubCommon>))]
[KnownType(typeof(Music))]
[KnownType(typeof(AppsAndPlugins))]
[KnownType(typeof(Notifications))]
[KnownType(typeof(Scenes))]
[KnownType(typeof(Skins))]
[KnownType(typeof(Ringtones))]
[KnownType(typeof(Alarms))]
[KnownType(typeof(Widgets))]
[KnownType(typeof(Wallpapers))]
[KnownType(typeof(Soundsets))]
public class HubCommon{}

In my *.svc.cs file I do the following

List<HubCommon> hubContent = _ldapFacade.GetResults(query);
        MemoryStream stream = new MemoryStream();
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(HubCommon));          
        serializer.WriteObject(stream,hubContent);

So essentially I am trying to serialize a List to Json but I get the following error on the "WriteObject" execution:-

The server encountered an error processing the request. The exception message is 'Type 'System.Collections.Generic.List`1[[HubContentCore.Domain.HubCommon, HubContentCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' with data contract name 'ArrayOfHubCommon:http://schemas.datacontract.org/2004/07/HubContentCore.Domain' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'

What am I missing here ?

Thanks in advance.

A: 

The type of your DataContractJsonSerializer is HubCommon but you are writing an object of type List<HubCommon> and HubCommon is not added to the KnownTypAttribute

rob waminal
Thanks !! Wayyy too much screen staring for a day ... missed that completely. Really appreciate it.
Cranialsurge