Error adding service reference: Type is a recursive collection data contract which is not supported

我怕爱的太早我们不能终老 提交于 2019-12-01 02:36:08

If you want to keep the reference to Newtonsoft.Json you could also leave Newtonsoft.Json out of the list of assemblies to check for reuse of datacontracts.

To do this: right click your service reference, then click Configure Service Reference...

Under "Reuse types in referenced assemblies" select the second option to specify in which assemblies to search for reused types and select all assemblies but uncheck Newtonsoft.Json

Try removing Newtonsoft.Json from your references and re-add your service reference.

I had this error at compile time when trying to return a JObject as the endpoint result.

I got around it by making the endpoint return object and having this kind of code:

[WebGet(UriTemplate = "SomeRequest?form_request={form_request}", ResponseFormat = WebMessageFormat.Json)]
public object SomeRequest(string form_request)
{
    dynamic result = new JObject();
    // some other code
    result.status = "success";
    return JsonConvert.SerializeObject(result);
}

The jQuery consuming the service via jsonp e.g. $.getJSON('<?>.svc/SomeRequest', 'form_request=' + webform_as_json, request_callback); then unpacks the serialized object like so:

function request_callback(response) {
    var json = $.parseJSON(response);
    if (json.status == 'success') {

Do you really mean to return a node in an arbitrarily deep tree?

If so, then instead of returning a JToken, first convert it to a string to get the JSon text. On the client end, you can Jtoken.Parse(yourstring) back into a JToken.

If not, then consider passing back the Value<T> and letting the serialization deal with T.

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