开发者

WCF application crash on passing IList

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]' (for operation 'GetLanguage', contract 'Service1') be开发者_Go百科cause it is not the exact type 'System.Collections.Generic.IList1[Econcordia.Language]' 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.

[OperationContract]
[WebGet(UriTemplate = "EconService/GetAllLanguage", ResponseFormat = WebMessageFormat.Json)]
public List<Language> GetAllLanguage()
{
    IList<Language> rtnLang = Language.GetAll();
    return rtnLang.ToList();
}

Hope it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜