1

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

[https://i.sstatic.net/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 !!

2
  • 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. Commented Dec 22, 2015 at 14:24
  • stackoverflow.com/questions/9594229/… Commented Dec 22, 2015 at 15:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I cant edit the service , so service code has to be remain like this only
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.