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

前端 未结 4 1877
你的背包
你的背包 2021-01-11 09:05

I tried to add a service reference to a WCF service that resides in the same solution from an ASP.NET MVC 4 project but failed. I got a error saying:

4条回答
  •  [愿得一人]
    2021-01-11 09:54

    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') {
    

提交回复
热议问题