1

I am consuming the .asmx service in my asp.net web api application like this :

[https://i.stack.imgur.com/WyyqX.png

but this service returns nothing, but in turn writes response in HTTP response object like this: ` [WebMethod(EnableSession = true)] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetResearchDocsBySector(int pageCode, int resultsPerPage, string subTypeIds, int timeframe) { JavaScriptSerializer js = new JavaScriptSerializer(); IRatingsDirectDataMgr dataMgr = RemoteUtil.GetRemote();

        List<ResearchDocumentDisplay> results = dataMgr.GetSolrResults(pageCode, resultsPerPage, subTypeIds, timeframe, false);

        List<ResearchDocumentWidgetDisplay> resultList = new List<ResearchDocumentWidgetDisplay>();
        foreach (var item in results)
        {
            var obj = ObjMapper<ResearchDocumentDisplay, ResearchDocumentWidgetDisplay>.Map(item);
            obj.ArticleTypeName = Constants.TypeMappings[obj.ArticleTypeId];
            resultList.Add(obj);
        }

        HttpContext.Current.Response.Write(js.Serialize(resultList));
    }`

I want to consume the result obtained from the service in my webapi application in json format how can we go about it ?

Note : I can't change the .asmx service code at all !!

  • Do not post code as images. We don't program with pictures. Pictures make it difficult to re-utilize your code in an answer, they can't be edited, and they can't be searched. Please edit your question to correct this. – mason Dec 22 '15 at 14:24
  • http://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-api – Amit Kumar Ghosh Dec 22 '15 at 15:39

1 Answers1

1

Set GetResearchDocsBySector to return your List rather than having a void return type and injecting it into the Current http content. TO do this you will need to mark ResearchDocumentWidgetDisplay as Serialisable which you do by adding [Serialisable] above your class ResearchDocumentWidgetDisplay.

Simon Houlton
  • 182
  • 1
  • 10
  • I cant edit the service , so service code has to be remain like this only – Naveen Kumar Dec 22 '15 at 15:33
  • It could come down to the service your calling not returning any results. Are you sure the parameters you're passing in return a result set? Secondly I would recommend running Fiddler on the request to make sure the results are being passed. – Simon Houlton Dec 22 '15 at 16:48