Self Hosted WCF Rest service ERROR : Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported

被刻印的时光 ゝ 提交于 2020-01-02 08:24:11

问题


I have a WCF Rest service that's self hosted. It works fine until I decided I have to use JToken (Newtonsoft.Json.Linq.JToken). I then got the error :

Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself.

I've seen all the answers from this post, this one and others. The fact is, I'm hosting my services within an internal program (in the company where I work, can't show it :-( ). I'm doing it exactly like it's self hosted, but the implementations and the interfaces of my services aren't as a WCF Service Library, just Class Library, so I can't access the menu they're talking about in the answers (where there's : "Reuse types in specified referenced assemblies").

I couldn't find any solution and I would like to use JToken.

Here's my service contract :

[ServiceContract]
    public interface ISearchService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "search/")]
        List<Client> SearchClient(JToken jsonBody);
    }

My hosting is done like in this post : How do I create WCF EndPointBehaviors in Code rather than the configuration? (I had to do it without a configuration file).

Hope my question is clear. Thank you for your help

来源:https://stackoverflow.com/questions/30759607/self-hosted-wcf-rest-service-error-type-newtonsoft-json-linq-jtoken-is-a-rec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!