I crated a WCF .Net 3.5 Rest service, it crashes when I pass IList interface. I’m using NHibernate to populate the list.
Here is my code:
[OperationContract]
[WebGet(UriTemplate = "EconService/GetAllLanguage", ResponseFormat = WebMessageFormat.Json)]
public IList<Language> GetAllLanguage()
{
IList<Language> rtnLang = Language.GetAll();
return rtnLang;
}
This is the error message:
Request Error
The server encountered an error processing the request. The exception
message is ‘Cannot serialize parameter of type
‘System.Collections.Generic.List1[Econcordia.Language]' (for1[Econcordia.Language]’
operation 'GetLanguage', contract 'Service1') because it is not the
exact type 'System.Collections.Generic.IList
in the method signature and is not in the known types collection. In
order to serialize the parameter, add the type to the known types
collection for the operation using ServiceKnownTypeAttribute.’. See
server logs for more details. The exception stack trace is:at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.ValidateOutputType(Type
type, Type parameterType, IList`1 knownTypes)
at System.ServiceModel.Dispatcher.SingleBodyParameterDataContractMessageFormatter.GetOutputSerializer(Type type)
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.CreateBodyWriter(Object
body)
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.SerializeReply(MessageVersion
messageVersion, Object[] parameters, Object result)
at System.ServiceModel.Dispatcher.ContentTypeSettingDispatchMessageFormatter.SerializeReply(MessageVersion messageVersion, Object[] parameters, Object result)
at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.SerializeReply(MessageVersion
messageVersion, Object[] parameters, Object result)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.SerializeOutputs(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
Any help would be appreciated.
You should return a concrete
List<Language>instead.Hope it works.