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

I have a WCF Rest service that is self hosted. It works great until I figured I should use the JToken ( Newtonsoft.Json.Linq.JToken ). I 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 have seen all the answers from this post , this one and others. The point is that I accept my services in an internal program (in the company where I work, I cannot show it :-(). I do it exactly the same as myself, but the implementations and interfaces of my services are not a library of services WCF, but only a class library, so I cannot access the menu they talk about in the answers (where is: "Reusable types in specified referenced assemblies").

I couldn't find a 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 and not setup? (I had to do this without a config file).

Hope my question is clear. Thank you for your help.

+3


source to share





All Articles